How to Create a JAR file in Linux

Create a Jar File

Created 3 sample files as file1.txt, file2.txt and file3.txt

 -bash-4.1$ ls
 file1.txt  file2.txt  file3.txt
 -bash-4.1$ jar -cvf test.jar *
 added manifest
 adding: file1.txt(in = 5) (out= 7)(deflated -40%)
 adding: file2.txt(in = 5) (out= 7)(deflated -40%)
 adding: file3.txt(in = 5) (out= 7)(deflated -40%)
 -bash-4.1$ ls
 file1.txt  file2.txt  file3.txt  test.jar

Unjar a Jar File

I used the Jar that is created above:

 -bash-4.1$ ls
 test.jar
 -bash-4.1$ jar -xvf test.jar
   created: META-INF/
  inflated: META-INF/MANIFEST.MF
  inflated: file1.txt
  inflated: file2.txt
  inflated: file3.txt
 -bash-4.1$ ls
 file1.txt  file2.txt  file3.txt  META-INF  test.jar
 -bash-4.1$

Leave a Reply