This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Creating a .jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Creating a .jar" Watch "Creating a .jar" New topic
Author

Creating a .jar

Sean Rhone
Greenhorn

Joined: Dec 13, 2004
Posts: 12
I hope this is the right section for this question. I have an J2EE application already (another programmer created it) and I want to try and create a .jar file containing all the .java files. My problem comes into play that there are multiple directories of these .java files. What is the command to invoke to create a .jar file to include all .java files in sub-directories?

Thanks for your help
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You can list multiple file or directory names at the end of the command line when you execute the jar command. If you specify a directory, then all subdirectories and files in that directory are included in the jar file. Let me illustrate with a simple example. Say you have the following directory hierarchy:

Then you can run the following command to create a JAR file:

I'd like to point out that I haven't actually run this example. In case it doesn't work exactly, you should just type "jar" at the command line. This will give you some simple help that should clarify what (if anything) I have done wrong in my example.

HTH

Layne


Java API Documentation
The Java Tutorial
Jeff Bosch
Ranch Hand

Joined: Jul 30, 2003
Posts: 804
You can also list the files and directories in a text file, and list the text file's name as a parameter to the jar command. This way you don't have to retype the list every time you need to change the jar.

Note: The jar command can tell the difference between a file and a directory. If it detects that a parameter is a directory, it will recursively include the directory contents.

See Sun's jar documentation for details.


Give a man a fish, he'll eat for one day. Teach a man to fish, he'll drink all your beer.
Cheers, Jeff (SCJP 1.4, SCJD in progress, if you can call that progress...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating a .jar
 
Similar Threads
jar files
jar
Remote debugging using Eclipse
Packing files to single encapsulated object
Jar files...dont know what is the problem