Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

java.lang.NoClassDefFoundError thrown when running jar file

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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



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



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.

The application is running without issues in eclipse.

 
Bartender
Posts: 1051
5
Hibernate Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What you are trying to achieve is not currently possible i.e. trying to run a class within a jar which requires jar files also contained with the same jar - see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648386.

The simplest solution is to extract the jars you have (in jars folder) and put them relative to your main jar file. Then add a Class-Path attribute to your Manifest file which provides this relative location.
 
Rancher
Posts: 989
9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can create the jar file manually :http://docs.oracle.com/javase/tutorial/deployment/jar/build.html
Add the dependent jars to the classpath using: http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi Poorav,

I have faced this problem too. I found out that the log4j jar used to get excluded in classpathentry tag in ".classpath" file during builds.

Check the ".classpath" file for your project in eclipse has the entry. Just a guess... hope it works

Rgds
Kalpesh Malbari
 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

James Boswell wrote:What you are trying to achieve is not currently possible i.e. trying to run a class within a jar which requires jar files also contained with the same jar - see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648386.



Thanks, is this still an issue with 1.6. Your suggestion definitely works after extracting the contained jar files.
 
E Armitage
Rancher
Posts: 989
9
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Poorav Chaudhari wrote:

James Boswell wrote:What you are trying to achieve is not currently possible i.e. trying to run a class within a jar which requires jar files also contained with the same jar - see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4648386.



Thanks, is this still an issue with 1.6.



Yes, the tutorial link (you should read those pages if you want to create and distribute jar file) says

Note: 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.

 
Poorav Chaudhari
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Armitage,

I'll look into this tutorial.

Poorav
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic