Why wont this jar execute (one way fine, the other is not)
Without using a executable jar this works fine:
java.exe -classpath myproject\classes;lib1.jar;lib2.jar;lib3.jar MyMainClass
MyMainClass is my target class stored in myproject\classes
I make an executable jar called Project.jar (basically all content in myproject\classes with usual manifest file containing target class) and then try
java.exe -classpath lib1.jar;lib2.jar;lib3.jar -jar Project.jar
This does not work and gives error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/beans/factory/InitializingBean
The class org/springframework/beans/factory/InitializingBean is contained in lib1.jar
I must be missing something fundamental about creating executable jars? Any ideas or pointers?
# 1
I've simplified my problem so someone could help me please!!!!
The following runs fine:
java -cp .;Model.jar Test
The following fails:
java -cp .;Model.jar -jar Test.jar
Exception in thread "main" java.lang.NoClassDefFoundError: Model at Test.main(Test.java:8)
Model.jar contains one class model.Model.class
Test.jar contains one class Test.class plus manifest file. The Test class simple does the following:
import model.Model;
public class Test
{
public static void main(String[] args)
{
System.out.println("Start");
Model model = new Model();
System.out.println("End");
}
}
Any ideas why?
# 2
Found answer on another web site. It seems daft to me but there you go
An executable JAR must reference all the other dependent JARs it requires through the Class-Path header of the manifest file. The environment variable CLASSPATH and any class path specified on the command line is ignored by the JVM if the -jar option is used.