Poorav
Poorav

Reputation: 415

java.lang.NoClassDefFoundError thrown when running jar file

I am trying to run my jar file on a Mac (Haven't yet tried on any other platform). When I run using java -jar MyApp.jar I get the following error

Stacktrace:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
at tabalchi.MyLogger.getLogger(MyLogger.java:51)
at tabalchiApp.TabalchiApp.printSystemProps(TabalchiApp.java:117)
at tabalchiApp.TabalchiApp.main(TabalchiApp.java:37)

So, as you can see the main class is recognized. This is the manifest file. --->

Manifest-Version: 1.0
Class-Path: . jars/log4j-1.2.16.jar jars/jfugue-4.1.0-20120125.jar jars/gervill.jar jars/AppleJavaExtensions.jar  
Main-Class: tabalchiApp.TabalchiApp
SplashScreen-Image: tabalchiApp/resources/splash.png

<--- And the folder structure in the jar file as follows. --->

META-INF/MANIFEST.MF
jars/AppleJavaExtensions.jar
jars/gervill.jar
jars/jfugue-4.1.0-20120125.jar
jars/log4j-1.2.16.jar
tabalchiApp/TabalchiApp.class   <-- this is the main class
tabalchiApp/otherClasses.....class

<---

I have read many posts about running .jar file but none of the solutions have worked for me. I would really appreciate your help on this one.

I am creating the jar file by exporting from eclipse. If I export to a runnable jar file then I cannot control the making of the manifest file. I need to add the splash image in the manifest file. And I am having some other issues with the runnable jar export. Hence this path.

Upvotes: 1

Views: 4854

Answers (3)

Poorav
Poorav

Reputation: 415

Ok, so according to this link,

http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

The Class-Path header points to classes or JAR files on the local network, not JAR files within the JAR file or classes accessible over internet protocols. To load classes in JAR files within a JAR file into the class path, you must write custom code to load those classes. For example, if MyJar.jar contains another JAR file called MyUtils.jar, you cannot use the Class-Path header in MyJar.jar's manifest to load classes in MyUtils.jar into the class path.

So, it seems I cannot include other jar files in my jar file.

Upvotes: 0

WineGoddess
WineGoddess

Reputation: 421

In which directory are you trying to use: java -jar MyApp.jar

You can specify the packages/directories in the classpath to be sure they are found.

Upvotes: 0

amicngh
amicngh

Reputation: 7899

It seems that log4j is missing.it is expecting jars/log4j-1.2.16.jar in class path .

jars/log4j-1.2.16 

should be under folder structure.

 jars/log4j-1.2.16.jar

Upvotes: 4

Related Questions