java decompile
Way
- Use Idea to directly view the imported jar package, or use the idea decompilation plug-in to convert the jar package into a java file
- Upload the jar package online for decompilation: http://www.javadecompilers.com/
- Download the tool yourself for decompilation
Experience
- It is best to use the idea decompilation plug-in to turn the jar package into a java file;
- Some other tools are too old, the results are very poor, and some character sets do not support and need to be adjusted
Idea to decompile
Enter the location where the jar package needs to be decompiled from the terminal of idea, and execute the following command
# mac
java -cp "/Applications/IntelliJ IDEA.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true ***.jar "/Users/***"
# windows
java -cp "D:\Program Files\JetBrains\IntelliJ IDEA 2021.3.2\plugins\java-decompiler\lib\java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true ***.jar "D:\Program Files\"
# 参数说明
1.idea自带的反编译插件我位置——"/Applications/IntelliJ IDEA.app/Contents/plugins/java-decompiler/lib/java-decompiler.jar"
2.需要反编译的jar包——***.jar
3.结果输出位置——"/Users/***"
After the result is output, it is still a jar file, just decompress it directly, and it is in .java format
encountered error handling
- I guess the reason for this problem is that idea comes with jvm version 11, and then this package is compiled using jdk11
- When running, it uses its own environment. 52 represents version 1.8. Compilation of low version can run compatible with high version, but compilation of high version cannot run in low version.
- So I installed another 11 version of jdk and the problem was solved
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler has been compiled by a more recent version of the Java Runtime (class file version 55.0), this version of the Java Runtime only recognizes class file versions up to 52.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:757)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:473)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)
The version corresponding to class version
Java 1.0 45.0
Java 1.1 45.3
Java 1.2 46.0
Java 1.3 47.0
Java 1.4 48.0
Java 5 49.0
Java 6 50.0
Java 7 51.0
Java 8 52.0
Java 9 53.0
Java 10 54.0
Java 11 55.0
Java 12 56.0
Java 13 57.0
Java 14 58.0
Java 15 59.0
Java 16 60.0
Java 17 61.0
Java 18 62.0
Java 19 63.0