java -cp "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3\plugins\java-decompiler\lib\java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true dbTool.jar mysrc
等指令运行完毕之后,会在指定的目录(示例是 mysrc)中生成的打包好的源码,一般是 jar 格式的压缩文件。反编译后的目录结构跟jar包是一样的,只不过是把class文件反编译成java文件。解压就可以看到源码文件了。
异常处理
JDK 版本不一致
报错如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
Error: A JNI error has occurred, please check your installation and try again 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:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:468) 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:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:495)
这是由于本地默认的 Java 版本与 InteliJ IDEA 插件版本的 JDK 不一致导致的,使用对应的 JDK 版本即可。如下所示:
1
E:\software\Java\jdk-11.0.1\bin\java.exe -cp "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2020.3.3\plugins\java-decompiler\lib\java-decompiler.jar" org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler -dgs=true dbTool.jar mysrc