I have a myfile.jar file. I use jd-gui to decompile all *.class in a folder in myfile.jar. I get many *.java files in many folders
After fixing some code in some *.java, now I would like to recompile all *.java back to *.class, and pack the whole folder back to myfile.jar.
How do I do this?
(This is my first time playing with java code.)
Before opening jar file just change the extension of jar to zip file and then extract that particular class file that you want to edit , then decompile it using any decompiler ,make the changes , compile it back and then finally put it back in the zip file. Hope it helps.
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.
You need a Java Development Kit (JDK). This includes a Java compiler (usually named javac
), and an jar archiver.
Assuming you have the java files in a directory names src
(then according to their package structure), you would use
javac -d classdir -sourcepath src src/*.java src/*/*.java src/*/*/*.java ...
to compile all files. (Adjust the number of * to the number of directory levels. If you only have some folders with source files in them, you can also list them individually. If some classes depend on others, you can ommit the others, the compiler will find and compile them automatically.)
If the program needs external libraries, provide these with a -classpath
argument.
Now we have all compiled classes in the directory classdir
. Look into your original jar file: any non-class files in there should also copied into your classdir (in the same relative directory they were before). This most notably includes META-INF/MANIFEST.MF
.
Then we create a new jar file from these. The jar
tool is included in the JDK.
jar cfm mypackage.jar classdir/META-INF/MANIFEST.MF -C classdir .
(You can also simply use a zip program of your confidence and rename the resulting zip file to .jar. If your files have non-ASCII names, make sure to set the filename encoding to UTF-8.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With