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.

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

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.

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).

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.

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

commented: What is the point to open old post and answer the question when same answer was already provided. If you want to answer the post please first read what others already said -1

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

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

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

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.