Java, Classpath, Classloading => Multiple Versions of the same jar/project

Classloader related problems are a quite complex matter. You should in any case keep in mind some facts: Classloaders in an application are usually more than a single one. The bootstrap class loader delegates to the appropriate. When you instantiate a new class the more specific classloader is invoked. If it does not find a … Read more

Gradle – no main manifest attribute

Try to change your manifest attributes like: jar { manifest { attributes( ‘Class-Path’: configurations.compile.collect { it.getName() }.join(‘ ‘), ‘Main-Class’: ‘hello.HelloWorld’ ) } } And then just change ‘hello.helloWorld’ to ‘<your packagename>.<the name of your Main class>’ (where your Main class has a main method). In this case, you make in your manifest an attribute, which … Read more

Execute another jar in a Java program

If I understand correctly it appears you want to run the jars in a separate process from inside your java GUI application. To do this you can use: // Run a java app in a separate system process Process proc = Runtime.getRuntime().exec(“java -jar A.jar”); // Then retreive the process output InputStream in = proc.getInputStream(); InputStream … Read more

How to use classes from .jar files?

Let’s say we need to use the class Classname that is contained in the jar file org.example.jar And your source is in the file mysource.java Like this: import org.example.Classname; public class mysource { public static void main(String[] argv) { …… } } First, as you see, in your code you have to import the classes. … Read more

How to list the files inside a JAR file?

CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream(jar.openStream()); while(true) { ZipEntry e = zip.getNextEntry(); if (e == null) break; String name = e.getName(); if (name.startsWith(“path/to/your/dir/”)) { /* Do something with this entry. */ … } } } else { /* Fail… */ } Note that … Read more

Building a fat jar using maven

Note: If you are a spring-boot application, read the end of answer Add following plugin to your pom.xml The latest version can be found at … <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>CHOOSE LATEST VERSION HERE</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> … After configuring … Read more

Differences between “java -cp” and “java -jar”?

I prefer the first version to start a java application just because it has less pitfalls (“welcome to classpath hell”). The second one requires an executable jar file and the classpath for that application has to be defined inside the jar’s manifest (all other classpath declaration will be silently ignored…). So with the second version … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)