First, we need to know that packaged Java programs are compiled bytecode files (*.class), which are loaded into the JVM at runtime.
If you want to replace a class, you just need to recompile the source code of that class and then replace the previous class file.
So what if there is no source code? This time we can use anti-compilation software to decompile the class file, anti-compilation software is more famous Jd-gui, can be downloaded from the official website to the latest version
I'm using jd-gui-0.3.6.windows here.
After downloading the class file or jar package into the Jd-gui window you can see the anti-compiled code ~nice, so the first step is done
The second step: we can copy the code, such as create a Xxx.java file in the class folder and copy the Xxx.class decompile code into it.
Step Three: We modify the code to save and compile it with Javac
Here's how to use Javac to compile Java files
In general, direct Javac + file path is possible, but if there are some dependencies you need to use the-classpath option.
Like we're here to compile a file named Importui.java, the directory format after unpacking the jar package is as follows:
Here you can see the Gmsimport folder is the place where the class file is stored, it is the classpath of this project, so you need to add this folder when compiling the file
We also saw 2 jar packages, and we need to write a different one for the jar package, for example, we are here to compile a Importui.java file (the current directory is here)
Javac-classpath D:\gmsimport;d:\gmsimport\datepicker-v0.99-2006.09.01.jar; Com\test\gmslic\importui.java
This compiles well, and the default path to the generated class file is the same directory as the Java file
Try the Java command to start it, also need to bring the-classpath option Oh ~
Java-classpath D:\gmsimport;d:\gmsimport\datepicker-v0.99-2006.09.01.jar; Com.test.gmslic.ImportUI
It's a modified effect, isn't it? Nice, we can replace the previous version with a package!
By the-classpath, the above can be shortened to-cp~.
Jdgui Anti-compilation +javac compilation = Passive File modification code