Advanced Java: How to decompile the jar package to obtain the source code

0 Preface

For some historical legacy projects that do not provide source code, or third-party jar packages, we often need to open them, but there is no source code. At this time, we need to decompile to obtain the project source code.

Of course, not all jars can be decompiled, some of which have been anti-compiled, but it is completely feasible to decompile the projects left over from our history

Today we will take a look at how to decompile

1. Decompile via JD-GUI

JD-GUI is an open source decompilation software, through which we can decompile the jar package more conveniently.

1. The download address is as follows

JD-GUI download address

insert image description here

2. After the download is complete, unzip the compressed package

insert image description here

3. Here I take the mac system as an example, double-click to open JD-GUIthe program in the decompressed folder

The new version of m1 chip mac may report the following error

insert image description here

The content of the prompt describes that jdk1.8 or above is required. In fact, this is not the reason. I am using jdk11 here. To solve this problem, a file needs to be modified

2. Right click JD-GUIand click显示包内容

insert image description here

3. Enter Contents/MacOSthe folder, open universalJavaApplicationStub.shthe file, and replace it with a new version of the file. The content of the new version of the file can be copied at the following address

https://raw.githubusercontent.com/tofi86/universalJavaApplicationStub/master/src/universalJavaApplicationStub

insert image description here

Because it is an external network address, some students may have problems accessing it, so I separately put the modified software package in the network disk address shown below, and can be downloaded directly if necessary

JD-GUI mac modified version network disk download address
Extraction code: vkcs

4. Double-click to open the software, and drag the jar package to be decompiled to the software interface

insert image description here

5. Select all files, click File-Save All Sourcesto save the decompiled source code, and select the save path

insert image description here

insert image description here

6. Wait for the decompilation to complete

insert image description here

7. After the decompilation is completed, BOOT-INF/classesyou can see the generated source code under the folder

insert image description here

So we get the source code we want, simple and fast! Of course, the generated source code will have some deviations in the folder structure, you only need to manually adjust it, and the core source code can be completely captured.

Guess you like

Origin blog.csdn.net/qq_24950043/article/details/127175159