954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to add a jar within another jar?

Hi,
I want to add a jar file to another jar file in such a way that my code should be able to access it(ie. internal classes of that jar).

Thanks in advance.

rdhiravani
Light Poster
37 posts since Jan 2007
Reputation Points: 10
Solved Threads: 2
 

just unzip the jar you want to use, place it in your .classes directory and make sure you have the right import statements.
should work just fine

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

i think you have to update your current jar file..

You have to use the following code

jar uf currentfilename.jar updatefilename.jar

just use this command then both jar files can be made as single.

vinod_javas
Practically a Posting Shark
871 posts since Feb 2007
Reputation Points: 119
Solved Threads: 7
 

nesting jarfiles isn't supported.
There are some proposals to allow for it, but nothing has yet reached prototype stage.

So at current the only way would indeed be to unpack the jars into one folder and repack them as a single archive.

Better (usually) to just add them all separately to your classpath.
It's a very rare case where there is a need to repack jars, usually it's only applicable when deploying packages to an application server where they would interfere with older versions of those same packages that the application server needs internally, a situation rare enough that most people never encounter it (I myself only have seen it once so far in a decade of using Java professionally).

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

Thanks to all for replying.

I found that packing a jar in other jar is possible(like any other file), but using the packages inside the jar is not possible.
The only way is to unpack the jar, & repack the classes of it in final jar file.

rdhiravani
Light Poster
37 posts since Jan 2007
Reputation Points: 10
Solved Threads: 2
 

unzip all jars in a directory and then make the new jar including all dependencies because
Nested Jar is still not Supported

puspendu
Newbie Poster
1 post since Jul 2007
Reputation Points: 9
Solved Threads: 1
 

how to unzip a jar file?

satish.paluvai
Light Poster
45 posts since Mar 2007
Reputation Points: 9
Solved Threads: 1
 

JAR files are normal zip files. Use any zipping software like Winrar or Winzip to open them.

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734
 

Or jar. jar can not just create jar files, it can also read and extract them.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

can u tell me the dos command for unzipping the jar file?

satish.paluvai
Light Poster
45 posts since Mar 2007
Reputation Points: 9
Solved Threads: 1
 

Just read the "tools" part of your JDK documentation on how to use the jar utility. The form of the command is going to vary with how you want to jar or unjar your files.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

There is no DOS command for unzipping jar files as DOS doesn't have a built-in system for interpreting the file format.
Maybe some DOS program can read and interpret the files (they're just ZIP files after all) but not DOS itself.
And you're certainly not going to run Java on DOS as Java has requirements that DOS never met.

jwenting
duckman
Team Colleague
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You