Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NoClassDefFoundError running a jar file from the command line  RSS feed

 
M Burke
Ranch Hand
Posts: 409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I made a jar file I want to execute on the command line. It has jar dependanies, so the other jars are packaged inside my main jar file in the \lib directory.

So I try to execute like this...>java -jar mainjar.jar
and I get a NoClassDefFoundError on all the depedancy jars.

I edit the manifest.mf to add the class path and executable main like this...
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 10.0-b22 (Sun Microsystems Inc.)
Main-Class: com.GenerateReports.test.TestCharts
Class-Path: lib\Generate.properties lib\jar1.jar lib\jar2.jar lib\jar3.jar



What am I missing?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't put the sub-jars inside the main jar; the class-path attribute refers to files outside of the main jar. The standard Java classloader does not have any idea how to load a jar inside a jar.
 
M Burke
Ranch Hand
Posts: 409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see. That is too bad, it would make deployment easier. Thanks for your help.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Burke wrote:Oh, I see. That is too bad, it would make deployment easier.


I agree, and I think many people do!
 
Rob Spoor
Sheriff
Posts: 21021
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe enough people will complain so Sun will rewrite the system class loader to handle JARs in JARs. Don't expect it though.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!