OS X上的Java:“打开”如果.app包中包含JVM包,则不会运行该命令 [英] Java on OS X: "open" command won't run if .app package contains a JVM bundle

查看:230
本文介绍了OS X上的Java:“打开”如果.app包中包含JVM包,则不会运行该命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从Java应用程序创建一个独立的Mac应用程序。我已经设置了.app目录,配置了 Info.plist 文件,在依赖项和Java运行时中都有。我成功地打开了.app并启动了程序,除了一个特殊的代码之外,一切正常:

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();

当我启动.app时,此代码似乎运行或者至少做任何事情。如果我打开包内容并启动.jar,它运行正常。我设法将其缩小到只有当.app包含Java运行时包时才会发生。由于运行.jar使用系统的Java并运行.app使用捆绑的Java,这就是我挣扎的原因。

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.

我的版本Mac安装的Java JDK应为1.8.0_77。
捆绑版本应为1.8.0_74。我从 Moneydance 应用程序中抓取它,因为我在制作我的.app时使用它作为参考。

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.

推荐答案

所以我会自己回答这个问题,因为这个问题在我身边。

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

我使用的捆绑JVM(我从Moneydance应用程序中复制过的)是罪魁祸首。我怀疑Moneydance的创建者可能已经剥离了他们的应用程序不使用的运行时捆绑功能,以减少文件大小。无论是什么原因,我的问题都是通过创建我自己的包修复的。

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.

我是通过复制 /Library/Java/JavaVirtualMachines/jdk1.8.0来实现的。 _77.jdk MyApp.app/Contents/PlugIns / 。之后我编辑了名为 JVMRuntime Info.plist 键,以使用条目 jdk1.8.0 _77.jdk 。我的应用程序现在使用这个JDK而不是我之前拥有的包,并且 open 现在可以正常工作。

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.

抱歉不做我的功课,但感谢帮助的人们。我在编写复制步骤时发现了这个问题,所以如果没有你,我可能没有找到它。我想我可以对可能遇到类似事情的人说的是检查你的JVM包。

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.

这篇关于OS X上的Java:“打开”如果.app包中包含JVM包,则不会运行该命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆