The Java bytecode comprising an application is commonly bundled and delivered in the form of a Java Archive (JAR) file.
Here I gonna start how to create JAR File
-open command
-go to ur files & folders destination and compile the java file then
-type:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
jar cvf <em><span style="text-decoration: underline;"></span></em><em><span style="text-decoration: underline;">filename.jar</span></em> <em><span style="text-decoration: underline;">l</span><span style="text-decoration: underline;">ist of files to be included in ja</span>r</em></pre for eg. [sourcecode='c'] jar cvf final.jar A.class B.class[/sourcecode] or alternatively[sourcecode='c'] jar cvf final.jar *.class[/sourcecode] <em><span style="font-style:normal;">Output looks like this</span></em> <em><span style="font-style:normal;"> </span></em> <em><span style="font-style:normal;"><img class="aligncenter size-full wp-image-172" title="jar1" src="http://javanepal.files.wordpress.com/2009/01/jar1.jpg" alt="jar1" width="341" height="62" /> </span></em> <em><span style="font-style:normal;">For <strong>inspection the content of JAR file</strong>.</span></em> <pre>jar tvf <em><span style="text-decoration: underline;">jarfilename.jar</span></em> |
for eg. [sourcecode=’c’]jar tvf final.jar[/sourcecode]
Output looks like this:
Using Bytecode contained with in a JAR file.
For informing the Java Virtual Machine that we want to use the bytecode of a JAR file, we use a code(command) option to set an environment variable called the classpath:
1 |
java –cp <span style="text-decoration: underline;"><em>path_to_jar_file</em></span><em> </em><span style="text-decoration: underline;"><em>class_which_contains_main_method</em></span> |
for eg.[sourcecode=’c’] java -cp final.jar A[/sourcecode]
Extracting Content of a JAR File
Here we can extract every files of jar file by the following command:
1 |
<span style="font-family:0;"> jar xvf <span style="text-decoration: underline;"><em>jarfilename.jar</em></span><em> </em><span style="text-decoration: underline;"><em>list_of_files_for_extracting</em></span></span> |
for eg.[sourcecode=’c’]
jar xvf final.jar A.class B.class[/sourcecode]
To extract everything from a JAR file, we’d type:
[sourcecode=’c’]jar xvf final.jar[/sourcecode]
Jarring Entire Directory Hierarchies
Here we are going to extract all the subfolder and all files of the folder in a single jar file.
1 |
jar cvf <span style="text-decoration: underline;"><em>jarFileName</em></span><em> </em><span style="text-decoration: underline;"><em>Main</em></span><span style="text-decoration: underline;"><em>DirectoryName</em></span> |
for eg. [sourcecode=’c’]jar cvf new.jar “C:JavaProject”[/sourcecode]
//don’t forget to put quote for the folder directory