- This topic has 3 replies, 2 voices, and was last updated 18 years, 5 months ago by Riyad Kalla.
-
AuthorPosts
-
BrianHMemberI’ve encountered a curious problem with deploying an application. Hopefully you can help me solve it or suggest what the cause might be.
My application runs just fine in the IDE. I exported it as a jar through the export wizard. There are three warnings, but they seem to be related to XML rather than the Java code.
If I try to run the jar from command line, I get a NoClassDefFoundError in main. If I run it using the -jar option, I get the same error but for org.apache.log4j.Logger. Paring down imports and increasing the heap size hasn’t made a difference. I’ve rebuilt and re-exported the app several times, checking to make sure all the libraries exist, are bundled with the jar, that the main class is identified in the manifest, and that the app and log4j are in the classpath. I still get the same error. To make matters worse, the app did run a couple of days ago and I’ve only made minor code changes since.
Any suggestions?
Thanks,
BrianC:\WSS\App>java WSS.satcomserver.Main
Exception in thread “main” java.lang.NoClassDefFoundError: WSS/satcomserver/MainC:\WSS\App>java -jar WSS.jar
Exception in thread “main” java.lang.NoClassDefFoundError: org/apache/log4j/Logg
er
at satcomserver.SATCOMServer.<clinit>(SATCOMServer.java:34)
at satcomserver.Main.main(Main.java:27)
Riyad KallaMemberMoving to OT > Soft Dev
Brian,
Simply exporting your JAR doesn’t export any of your dependencies. You need to figure out all your dependencies and either specify them in a MANIFEST.MF file or include them in the run path like:
java -cp log4j.jar;library.jar;something-else.jar;WSS.jar WSS.satcomserver.Main
BrianHMemberOK, thanks. Bear with me, please, while I make sure I understand. In your example, I take it the -cp is relative to the current directory, since I’m at the command prompt. The export wizard creates a manifest, but doesn’t necessarily populate it from either the library list or the import statements (shucky-darn 🙁 ). So I need to add any jars that aren’t part of the java hierarchy (i.e., add log4j.jar but not java or javax). Then, after I modify the manifest, export the jar with the manifest in it. Should I include all of the library jars in the manifest, or do them one-at-a-time until it runs? I’m still confused over the fact that the jar ran a couple of days ago, but didn’t after I rebuilt it. Did I just get lucky the first time?
Thanks for the help.
Brian
Riyad KallaMemberI take it the -cp is relative to the current directory, since I’m at the command prompt. The export wizard creates a manifest, but doesn’t necessarily populate it from either the library list or the import statements (shucky-darn 🙁 ). So I need to add any jars that aren’t part of the java hierarchy (i.e., add log4j.jar but not java or javax).
Exactly. If you don’t want to get fancy with a MANIFEST file, just write a batch file or script to launch your app from the current dir. Having the manifest allows you to set the classpath and a Main-Class so folks can double click on it and run it, that’s kinda cool.
Then, after I modify the manifest, export the jar with the manifest in it. Should I include all of the library jars in the manifest, or do them one-at-a-time until it runs? I’m still confused over the fact that the jar ran a couple of days ago, but didn’t after I rebuilt it. Did I just get lucky the first time?
Depends, your exception looks like the JVM is not finding Log4J in your classpath, so you can either fix that by changing the MANIFEST or by including it on the command line by using -cp (short for classpath).
-
AuthorPosts