views:

80

answers:

5

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

+3  A: 

Jar files aren't "compiled" in the normal sense of the word. But you just create one with the jar command:

jar cvf myfile.jar file1 file2 etc

You can use globbing as normal:

jar cvf ../myfile.jar *

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

Note that for an executable jar file, you'll need to specify the manifest file as well.

Jon Skeet
A: 

Jar files usually contain compiled java files (class-files) and resources. If you are allowed to make changes on this jar, you could disassemble the class files using JAD and after recompilation assemble them again with the command jar

How did you edit a jar file, hex editor?

stacker
A: 

If you have the source code recompile it and make a new jar file

Alex Mathew
A: 

A jar file is just a zip file with a few extra files. You Can use any zip utility to rejar an unjarred jar file.

Thorbjørn Ravn Andersen
+1  A: 

How did you edit it?

Anyway, jar files follow the same format as regular zip files. If you want to update the content of the jar ( probably with a new file ) you could do:

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

That would update your jar with the file path/to/updated/Class.class If there's already a class with that name in that path, it would be replaced. If is not it would be created.

After this your jar is up to date.

OscarRyz