Hello everybody,

this is the first time I'm going to create a real-life JAR, so maybe a bit stupid question but I'm totally out of ideas here...

Okay, I have a project named WiWClient which depends on other project named common and requires libraries from lib (there are like 20 JAR files). What I need is to somehow put this all together and create a JAR file which will containt everything required.

I go WiWClient->Export -> Java -> JAR file. On the first screen (select resources to export) I can only select WiWClient and common but not lib. This creates JAR file containg all .class files from both projects, but no libraries from lib.

In WiWClient -> Project Properties->Java Build Path I have all JARs from lib listed under Libraries and OrderAndExport.

Can you please give me an advice what I need to do to have everything required included in one JAR which can be then deployed to our server?

Thanks a lot in advance!
Adam

Recommended Answers

All 8 Replies

create a JAR file which will containt everything required.

You might not need to put the contents of the other jar files into your jar file. The manifest file has a record/line where you can specify other jar files: Class-Path:

One of my manifest files:

Main-Class: CmprFolders
Class-Path: DocumentViewerWParser.jar

Is your question about how to use the jar command
or is it about how to use an IDE?

You totally misunderstood my question.

My aim is to put every external library jar files into single jar file.

Basically , i want to put all the required libraries, resources everything into single jar file , so that i can use one single jar file .

There are some external third party libraries i use in my code( ex- speech recognition, synthesis etc) . So while building jar file for my application , i want to add these external libraries into it and make it as single jar file.

Hope you understand..

Thanks in advance

I'll assume you are using Eclipse here. IIRC, Eclipse "Export JAR" doesn't have the option to collpase the dependency jars into a single JAR. For this to work, just make sure you have a dummy (or necessary) main class in your project. Then click Export -> Runnable JAR. Options 1 and 2 provide you the choice to have dependent JARs collapsed into the given JAR.

If not Eclipse, you can always try out One Jar but I personally have no experience with it.

put all the required libraries, resources everything into single jar file , so that i can use one single jar file .

Extract everything from all the other jar files and use the jar command to put all the extracted files into the single jar file.

@ S.o.S ..

Thanks for your valuable suggestion. I am using netbeans. Anyway i will try "one jar" link that you gave. Let me check if it works or not..
Anyidea for doing that in netbeans.?? Thanks again @S.o.S

@Norm1 : I got that idea long before. But it is very tedious.Extracting very large external jar files(that too 10-15 jar files) is not an easy task. Again intigrating them into single jar file after extracting such bunch of jar files leads to confusion and also different issues(name collisions etc).It will not work (eventhough i never tried, i am confident to say that because i am using so many external jar files.) Anyway Thanks for your reply.

You may be rejecting Norm's advice too quickly. Opening 15 files in WinZip or whatever and drag/drop everything into your jar is trivially easy, and shouldn't take more than a few minutes. And the package name/directory structure was designed to guarantee no name clashes.

What if i have same class names in two different jar files. Is that not a name clash if i extract both the jar files? And there are so many class files and resource files in a jar file. Thousands of variety type of files will be there in a jar file with different hirearchy of directories. Imagine the situation where i am extracting some 20 jar files and that jar files contains thousands of different files . The situation will be worse and clumsy. Extracting with winrar or some other tool is not a problem, but integrating them is a big problem.
So keeping all this in mind,i dropped the idea. This will be my least least option , if i dont find any other methods to do so for making one jar file.
I doesnt mean to totally neglect the idea but it will be my least option.

Still open to any other solutions while i am trying this "One jar".

Thanks

When you copy stuff into your jar its necessary that you copy the complete hierarchical directory structure, not just the class files. That's fundamental to how java packages work. Just copy the few top-level directories, you don't need to know or care exactly what's inside them, and there is no "integration" needed.
Currently the compiler and runtime find all the files they need by searching the classpath, which includes all your jars. By moving the top-level directories into your jar you are just moving them from one place in the classpath to another. It really is trivial.

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.