Sometimes I need to know what’s inside to figure out a best solution, like modifying a Java
.class file in a
After searching google and stack overflow for a while, I found this question is little cared, and almost all information is not complete.
So I wrap them up and make the whole process runnable.
Use luyten (or JD GUI if you don’t care its bugs) to decompile the jar, and save all files to folder
Modify a java file, then compile it to
cd srcdir vi com/.../A.java cp some_folder/original.jar ./ javac -cp "original.jar" com/.../A.java
The last command will generate a file named
A.class in the same folder as
Use luyten to check if the file
A.class is modified.
jar -uf original.jar com/.../A.class mv original.jar modified.jar
This will generate a
modified.jar. Use luyten to check again if it’s modified.
A.java depends other external jars other than
original.jar, Add them to classpath by
javac -cp "original.jar;lib/*" com/.../A.java
It’s important to use
lib/* rather than
lib/*.jar because the later will not work.