Hello, I want to create a jar file which can be run simply by clicking on it. Here are the steps which I have followed. I have created a manifest file which has a listing of main class. Created jar file using -jar option available in java. Now the problem is when I try to run this jar file, it gives this error: Exception in thread "main" java.lang.NoClassDefFoundError: Though all necessary jar files are included in classpath. Small Note: When I try to run class files, it runs fine. Pls help me out. Thanks and Regards,
How did you create the jar file? Does the Jar file structure follows the package structure? Also, did you run the application using: java -jar [your_jar.jar] [your_application] instead of java -classpath [your_jar.jar] [your_application] Nick
One suggestion I don't see here is the Class-Path entry in the manifest file. Have you tried setting your classpath there. Below is an example Manifest-Version: 1.0 Created-By: Apache Ant 1.5 Main-Class: Main Class-Path: castor-0.9.5.jar dom4j.jar c3p0.jar commons-collections.ja r odmg.jar xerces.jar xalan.jar commons-logging.jar hibernate2.jar eh cache.jar cglib2.jar db2jcc.jar db2jcc_license_cu.jar j2ee.jar Absolu teLayout.jar
First: I guess this is a beginners question. Can someone move it? Second: If you put a blank after the name of the class which contains a main-method, (or .class) in the manifest, it will fail. (edited for typo) [ March 25, 2004: Message edited by: Stefan Wagner ]
Your Main-classes name is really 'MainClassName'? (don't really believing). Try
and post the 'test.tmp' to the forum. It's essential to use the right starting-directory when creating the jar, using paths and jars. Don't replace the output with something more readable when posting to the forum. This is polite and appropriate, when first asking your question, but since the answers don't help, we have to get into the details.
Here are the details of the temp file. META-INF/MANIFEST.MF chatdev/ChatClient$1.class chatdev/ChatClient$2.class chatdev/ChatClient$CloseListener.class chatdev/ChatClient$EnterListener.class chatdev/ChatClient$SendListener.class chatdev/ChatClient.class
Sheesh, you guys... this ain't hard. When you execute java with the "-jar" flag it ignores your environment CLASSPATH variable and the java "-cp" and "-classpath" flags. Using the Class-Path manifest file entry is one way around this. The class path entries are filesystem based, relative to where the jar file is being executed from. Another way is to unjar dependent jars and jar them back up into the application jar. Another way is to provide a simple executable (exe, bat, sh, whatever is suitable for any likely target environments) that does it the old-fashioned way. Another way is WebStart. Lots of solutions. I personally like the "wrapper that calls java with the classname" as that provides a lot more flexibility in terms of setting the classpath, using or integrating the user's existing CLASSPATH, etc. Dave