Programmers inevitably borrow code from other Java projects. But sometimes only.calss files, JARs, or WAR packages are available, requiring programmers to be skilled at decompilating these types of files into Java code and producing a compilable project. The decompiler tool described in this article is JD-GUI. The decompiled JAR is a JAR for a SpringBoot project.

The decompilation tool is used

After downloading JD-GUI, unzip it without installation. Double-click to open the EXE file.

Open File selects the JAR package to decompile,



If you open it, you can see the Java source code file in the left classes->com directory

Click the file you want to view, you can see the source code, click the underlined variable symbol, it will automatically jump to the definition, you can also search the variable name, but the search will be slow, need to wait a little longer.

Get the source code

You can only look at the code. To compile, modify, and run the code, you have to extract all the code and form the project. Click file-> to save all source



The source code is saved as a zip package



The zip package is unpacked in three folders



The Java code is all in boot-inf /calsses/com



Copy everything in the classes directory into the empty SpringBoot project that you created, with the directory level copied correctly.

Get the project configuration file

Copy the contents of the project configuration files application.properties and pom.xm from the decompile directory with the same name and paste them in.

Get the JAR packages that the project depends on

Now that you have the project code, you have the configuration file, but you generally don’t run the project successfully. Because the POM decompiled is not particularly accurate, it is possible that many projects need packages that have no import in the POM. Or some of the JAR packages used by the original project were originally imported manually into the project, not uniformly managed by POM. The best way to do this is to extract all import JARs from the decompiled JARs.

Change the suffix test01.jar to zip test01.zip and unzip it to the current folder.



The unpacked boot-inflib contains all the JARs needed by the project. Add all the JARs to the project by adding external JARs.

Run the project

This is close to running the project successfully, because the decompilated code is not particularly accurate, and some of the code needs to be manually analyzed and modified, or if the modification is not successful, it has to be commented out before it can be compiled. Some packages may report errors at runtime, mainly due to conflicts between packages introduced by the POM and packages imported by hand, or some packages may have incorrect versions, which need to be resolved one by one. Of course, some decompiled projects just run correctly with no errors, which is better.