Compressing an Extracted Jar File
Asked Answered
S

4

5

I have extracted a jar file and made some change on it. Now, how can i compress again it as an executable jar file?

Thanks.(Sorry for my bad english.)

Sidedress answered 18/6, 2014 at 7:22 Comment(1)
Hopefully this answer be of some help on the topic :-)Piet
I
8

Try :

jar cf jar-file input-file(s)

according to http://docs.oracle.com/javase/tutorial/deployment/jar/build.html

Illfounded answered 18/6, 2014 at 7:33 Comment(2)
When I want to execute the resulting jar file I get the error: no main manifest attribute,Sinkhole
I used this command to compress folder into jar: jar cf fileName.jar FOLDER_NAME/Hoodoo
T
1

By Using Eclipse IDE You can Create your jar file

Below i have one link from which you can learn how to make jar file executable

https://www.cs.utexas.edu/~scottm/cs307/handouts/Eclipse%20Help/jarInEclipse.htm

But For that You have to make project in Eclipse.

Thimerosal answered 18/6, 2014 at 7:25 Comment(2)
It's not a eclipse project. It's jrupy-complete.jar file and it contains different subfolders and meta-inf folder.Sidedress
than you have to convert into project than make changes as per your requirenmnt and generate jarThimerosal
M
0

You can use this very simple library to pack/unpack jar file programmaticaly

JarManager

Very simple

import java.io.File;
import java.util.List;

import fr.stevecohen.jarmanager.JarUnpacker;

class Test {
   JarUnpacker jarUnpacker = new JarUnpacker(); 
   File myfile = new File("./myfile.jar");
   File unpackDir = new File("./mydir");

   List<File> unpacked_files = jarUnpacker.unpack(myfile.getAbsolutePath(), unpackDir.getAbsolutePath());
}

You can also use maven dependency

<dependency>
    <groupId>fr.stevecohen.jarmanager</groupId>
    <artifactId>JarManager</artifactId>
    <version>0.5.0</version>
</dependency>

Check the last version with the link bellow to use the last dependency

Please use my public issue tracker if you find some bugs

Monetmoneta answered 20/9, 2015 at 16:38 Comment(0)
B
0
jar cvf filename.jar *
  • To compress all extracted file to single jar file you can use *
  • To add single file you also can use filename instead of *

https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

Bequest answered 20/7, 2022 at 17:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.