Java on OS X: “open” command won't run if .app package contains a JVM bundle

拈花ヽ惹草 提交于 2019-12-12 03:44:56

问题


I'm trying to create a self-contained Mac app from a Java application. I've set up the .app directory, configured the Info.plist file, baked in dependencies as well as a Java runtime. I am successfully able to open the .app and launch the program and everything works except for one peculiar piece of code:

ProcessBuilder pb = new ProcessBuilder("open", "/Applications/TextEdit.app");
pb.start();

When I launch the .app, this code does not seem to run or at least do anything. If I open the package contents and launch the .jar, it runs fine. I managed to narrow it down to happen only when the .app contains a Java runtime bundle. Since running a .jar uses the system's Java and running the .app uses the bundled Java, this has got to be the reason I'm struggling.

The version of my Mac's installed Java JDK should be 1.8.0_77. The bundled version should be 1.8.0_74. I grabbed it from the Moneydance application as I used it for reference when making my .app.

Any help is very appreciated as this should be the final step to release it. I created this question to be more specific than my other question here.


回答1:


So I'll answer this myself as the issue was somewhat on my side.

The bundled JVM I was using (that I had copied from the Moneydance application) was the culprit. I suspect that the creators of Moneydance might have stripped their runtime bundle of features their app doesn't use in order to reduce the file size. Whatever the reason, my issue was fixed by creating my own bundle.

I did so by copying /Library/Java/JavaVirtualMachines/jdk1.8.0_77.jdk to MyApp.app/Contents/PlugIns/. After that I edited the Info.plist key called JVMRuntime to use the entry jdk1.8.0_77.jdk. My app now uses this JDK instead of the bundle I previously had, and open now works as it should.

Apologies for not doing my homework, but thank you to the people helping. I found the issue while writing reproduction steps, so I might not have found it without you. I guess all I can say to those who might experience something similar is to check your JVM bundle.



来源:https://stackoverflow.com/questions/36693058/java-on-os-x-open-command-wont-run-if-app-package-contains-a-jvm-bundle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!