OS X Java .app包无法打开其他应用程序? [英] OS X Java .app bundle cannot open other apps?

查看:195
本文介绍了OS X Java .app包无法打开其他应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为OS X编写了一个Java SWT应用程序,将其导出为.jar并将其捆绑到.app中。一切都符合预期,除了我的应用程序中的关键部分;它需要打开其他应用程序。

I've written a Java SWT application for OS X, exported it as a .jar and bundled it into .app. Everything works just as expected except for a critical part within my app; it requires to open other apps.

我尝试过 Runtime.exec(); 以及 ProcessBuilder 执行此操作,在我需要启动的其他应用程序上调用打开命令。这可以从Eclipse完美工作,或者如果我通过终端启动我导出的.jar。但是,通过双击.app开始,它不起作用。

I've tried Runtime.exec(); as well as ProcessBuilder to do this, calling the open command on the other apps that I require to launch. This works perfectly fine from Eclipse or if I launch my exported .jar through Terminal. It does, however, not work when started by double-clicking the .app.

我想知道这是否是我的错误,或者是由Java或OS X.因为Mac应用程序是沙盒(从我所了解的),这可能是为什么调用从应用程序中打开什么也没有?

I'm wondering if this is an error on my part, or a restriction by either Java or OS X. Because Mac apps are sandboxed (from what I understand), could this be why calling open from within an app does nothing?

我用了两种方法来打开我需要的应用程序。这是一个蒸汽游戏,但也是零售,所以它可以通过应用程序本身或使用 steam:// 协议启动。在我的代码中,我尝试了以下内容:

I've used two approaches to opening the app I need. It's a Steam game, but also comes as retail, so it can be launched either through the app itself or using the steam:// protocol. In my code I have tried the following:

ProcessBuilder pb = new ProcessBuilder("open", "steam://rungameid/57300//");
pb.start();







ProcessBuilder pb = new ProcessBuilder("open", appDir);
pb.start();

appDir 是一个包含路径的字符串对于我想要开始的.app包。

appDir is a string that contains a path to the .app bundle I wish to start.

任何想法,为什么这种失败从Mac应用程序包,但运行良好的Eclipse / Jar?使用控制台运行应用程序(通过捆绑包中的bash脚本)不会返回任何错误,所以在我看来,Java运行命令很好,但是OS X可能会忽略它?

Any ideas why this fails from a Mac application bundle, but runs fine from Eclipse/Jar? Running the app with console (through the bash script in the bundle) does not return any errors, so it seems to me that Java runs the command fine, but that OS X perhaps ignores it?

我也尝试过在Google上搜索这个,但这似乎也是非常罕见或非常具体的,我无法找到任何东西。

I've also tried searching on Google for this, but it seems perhaps highly uncommon or just very specific and I wasn't able to find anything.

推荐答案

我自己回答这个问题,因为问题是我自己的设置。具体来说,它是我使用的捆绑运行时。我在另一个问题上写了一个更深入的答案:

I'm answering this myself because the problem was my own setup. Specifically it was the bundled runtime I was using. I wrote a more in-depth answer in my other question here:

OS X上的Java:如果.app包包含JVM捆绑

这篇关于OS X Java .app包无法打开其他应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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