Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you recompile a jar file?

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?

like image 799
Kyle Avatar asked Jul 28 '10 06:07

Kyle


People also ask

How do I recompile a Java file?

Open a command prompt window and go to the directory where you saved the java program. Assume it's C:\. Type 'javac MyFirstJavaProgram. java' and press enter to compile your code.

How do I edit a JAR and recompile?

On your first question JD-GUI is just a viewer you need to use dex2jar to retrieve the JAR file; decompile and save the classes you need to change; import JAR and JAVA files in your Android Studio; modify; recompile and repackaged.


2 Answers

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.

like image 165
Jon Skeet Avatar answered Nov 15 '22 06:11

Jon Skeet


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.

like image 40
OscarRyz Avatar answered Nov 15 '22 06:11

OscarRyz