How do you recompile the jar file?

I took the old jar file and edited it. Now I have a folder that has all the files in it, and I want to recompile them back into a jar file. How to do it?

+4
source share
4 answers

Jar files are not "compiled" in the normal sense of the word. But you just create the jar command:

 jar cvf myfile.jar file1 file2 etc 

You can use globbing as usual:

 jar cvf ../myfile.jar * 

Run jar -? or read the docs for more information.

Note that for the jar executable, you also need to specify the manifest file.

+10
source

How did you edit it?

In any case, jar files follow the same format as regular zip files. If you want to update the contents of the jar (possibly with a new file), you can do:

 jar -uf yourJar.jar path/to/updated/Class.class 

This will update your jar with the file path/to/updated/Class.class If there is already a class with the same name in this path, it will be replaced. If not, it will be created.

After that, your bath is updated.

+6
source

Jar files usually contain compiled java files (class files) and resources. If you are allowed to make changes to this jar, you can parse the class files using JAD and after recompiling build them again using the jar command

How did you edit the jar file, a hex editor?

0
source

A jar file is just a zip file with a few extra files. You can use any zip utility to recolor an unexpected jar file.

0
source

All Articles