Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to include jar in jar

 
seetharaman jayaraman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
salvin francis
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
seetharaman jayaraman
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 1268
10
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hmm, good
 
VarunKumar Mallisetty
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One Jar tries to solve this problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic