Mac 打开JD-GUI报错:ERROR launching ‘JD-GUI‘
ERROR launching 'JD-GUI'
You need to have JAVA installed on your Mac!\nVisit http://java.com for more information...
解决方案
找到JAVA_HOME
$ echo $JAVA_HOME
/Users/Shared/jre/
修改/Applications/JD-GUI.app/Contents/MacOS/universalJavaApplicationStub.sh
/Users/Shared/jre/bin/java -jar /Applications/JD-GUI.app/Contents/Resources/Java/jd-gui-1.6.6-min.jar
原因
我下载的 JD-GUI包内容是这样:
找报错信息
用命令行执行
cd /Applications/JD-GUI.app/Contents/MacOS
sh universalJavaApplicationStub.sh
有报错
Exception in thread "main" java.lang.IllegalAccessError: class org.jd.gui.OsxApp (in unnamed module @0x6bc168e5) cannot access class com.apple.eawt.Application (in module java.desktop) because module java.desktop does not export com.apple.eawt to unnamed module @0x6bc168e5
at org.jd.gui.OsxApp.main(Unknown Source)
这里有连个类: org.jd.gui.OsxApp & com.apple.eawt.Application
定位源码
package org.jd.gui;
import com.apple.eawt.Application;
public class OsxApp extends App {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
// Create an instance of the mac OSX Application class
Application application = Application.getApplication();
App.main(args);
// Add an handle invoked when the application is asked to open a list of files
application.setOpenFileHandler(e -> controller.openFiles(e.getFiles()));
// Add an handle invoked when the application is asked to quit
application.setQuitHandler((e, r) -> System.exit(0));
}
}
JD-GUI源码引用了com.apple.eawt.Application,但我们的jdk环境并没有这个类。
如何解决?
我估计com.apple.eawt在旧版本Mac存在,但mac升级后,com.apple.eawt就弃用了。所以我们只要避开OsxApp引用到的Application就可以了。
方案已经写在文章开头