Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating a .jar

 
Sean Rhone
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Jeff Bosch
Ranch Hand
Posts: 805
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic