aspose file tools*
The moose likes Beginning Java and the fly likes how to include jar in jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to include jar in jar" Watch "how to include jar in jar" New topic
Author

how to include jar in jar

seetharaman jayaraman
Ranch Hand

Joined: Feb 18, 2008
Posts: 43
Hi all,
I can able to create and executes jar files containing my packages and classes. But, how to include some jar files (like jmf.jar, etc) into my jar file. It creates properly, but results in Exception in thread "main" java.lang.NoClassDefFoundError:

Ex: test folder contains TestHello.java and a package hello.
This hello package contains Hello.java
...\test\classes>jar -cvfe hello.jar TestHello *.* - creates and executes properly (java -jar hello.jar displays output properly)

But, ...\test\classes>jar -cvf hello1.jar hello\*.* - creates jar file, hello1.jar
...\test\classes>jar -cvfe hello.jar TestHello TestHello.class hello1.jar - creates hello.jar properly
...\test\classes>java -jar hello.jar results in Exception in thread "main" java.lang.NoClassDefFoundError: hello/Hello

please help in including jar into jar!!!


Seetharaman Jayaraman
Only Change is Changeless
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
jar files can't be inside of other jar files if you want them to be found by the classloader. You'll need to keep separate jar files, or to repackage all class files into a single jar file.


Ping & DNS - my free Android networking tools app
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

1. It can be done.
2. It should not be done, I do not see any use of doing it here

You can include a folder "lib" for example and add external jar files there.
In that way, if a jar file has to be updated the client has to just replace the existing files in the folder.

A jar file is like a Zip file, you can include any files in it.

If i am not wrong, wht you are attempting to do it to allow your entire application into 1 single jar file.


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
seetharaman jayaraman
Ranch Hand

Joined: Feb 18, 2008
Posts: 43
yes, thanks to all.
Finally I extracted the required jar files into respective folders.
Added the required packages (referred in our java source files with import, etc) from them into my jar with my packages and class files.
problem solved.
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 928

hmm, good
VarunKumar Mallisetty
Ranch Hand

Joined: Jun 18, 2006
Posts: 31
One Jar tries to solve this problem.


SCJP 6.0
 
 
subject: how to include jar in jar