问题
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