Creating a JAR file to run from command line - Class not found
800467Sep 30 2009 — edited Sep 30 2009Hi all
I have created a JAR file by using the following command line instructions in DOS:
jar cmf C:\Java\manifest.txt test.jar C:\Java\classes
The C:\Java\classes location contains my package structure e.g. com\level1\level2\level3\ which contains all the .class files that I am interested in including the class that I want to run which contains the main method: HelloWorld
I have specified in the manifest file the following:
Manifest-Version: 1.0
Created-By: 1.6.0 (Sun Microsystems Inc.)
Main-Class: com.level1.level2.level3.HelloWorld
Now when I try and run the jar file from the command line using the following command:
java -jar test.jar HelloWorld
I get the following exception:
Caused by: java.lang.ClassNotFoundException: HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: HelloWorld. Program will exit.
I cannot understand why this is happening. I looked inside the JAR file - should there be a package structure in there for the HelloWorld class? Currently there is not one but I thought the creation of the JAR file using the command above this would be done automatically?
Thanks for any suggestions...