Wednesday

jar file crete - how to

Every one while working with java comes to a need for jar file creation. Here we will look at how to do all these in straight forward way.

What is jar file?

jAVA arCHIEVE --JAR files are Java's version of ZIP files.

Used for 2 purposes.

1.compress (make a smaller size) a number of files into one file (archiving).

2.To make a Java executable JAR file.

Details:

Compress Files To A Java Archive (JAR):

Syntax -> jar CF example.jar *.java

jar

The command to run the jar utility.

CF

Create a new archive with the file name specified. These two options are from this list of common options:

- c create new archive
- t list table of contents for archive
- x extract named (or all) files from archive
- u update existing archive
- v generate verbose output on standard output
- f specify archive file name
- m include manifest information from specified manifest file
- 0 store only; use no ZIP compression
- M do not create a manifest file for the entries
- i generate index information for the specified jar files
- C change to the specified directory and include the following file

Multiple options can be used together. They all must appear after the "jar" command with no white space separating them.

example.jar

Name of the JAR file. This can only be included if you use the 'f' option.

*.java

i.e. All files that have extension as .java .similarly you can write like *.class to make all your successfully complied java code (byte code) to make as an archive.

Names of all the files you want to put in the jar file. This could be just one name or a list of multiple names separated by space. Names can use pattern matching characters to match multiple files.

If you have 2 java file and you want to make a jar for them.


jar CF example.jar One.java Two.java

example.jar the name you want for your archive .
two.java your second file name.









Yes that’s enough to create a jar file or make a jar file for your files.


Next To make a Java executable JAR file.

No comments: