aspose file tools*
The moose likes Java in General and the fly likes NoClassDefFoundError running a jar file from the command line Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "NoClassDefFoundError running a jar file from the command line" Watch "NoClassDefFoundError running a jar file from the command line" New topic
Author

NoClassDefFoundError running a jar file from the command line

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 382
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
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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.


[Jess in Action][AskingGoodQuestions]
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 382
Oh, I see. That is too bad, it would make deployment easier. Thanks for your help.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

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

Joined: Oct 27, 2005
Posts: 19543
    
  16

Maybe enough people will complain so Sun will rewrite the system class loader to handle JARs in JARs. Don't expect it though.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NoClassDefFoundError running a jar file from the command line
 
Similar Threads
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError
NoClassDefFoundError