[英]Running Java from an OSX “.app” bundle causes “Error -10810”
This was tested on OSX Mavericks through virtual box, and on Yosemite on a macbook. 这已通过虚拟盒在OSX Mavericks上进行了测试,在Macbook上在优胜美地上进行了测试。
I have a simple executable jar named "HelloWorld.jar". 我有一个名为“ HelloWorld.jar”的简单可执行jar。
I am trying to create a .app bundle for this java application. 我正在尝试为此Java应用程序创建一个.app捆绑包。 (Obviously, my actual program is more complex, but I have whittled it down to the barest problems).
(显然,我的实际程序更复杂,但我将其缩减为最棘手的问题)。
At the console I type 在控制台上,我键入
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I view test-output.txt and see the expected output. 我查看了test-output.txt并看到了预期的输出。
I make a simple bash script named test
: 我制作了一个简单的bash脚本,名为
test
:
#!/bin/bash
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I chmod +x test
and then type ./test
, I view test-output.txt and see the expected output. 我
chmod +x test
,然后键入./test
,我查看了test-output.txt并看到了预期的输出。
mkdir -p test.app/Contents/MacOS
cp test test.app/Contents/MacOS
open test.app
I view test-output.txt and see the expected output. 我查看了test-output.txt并看到了预期的输出。
File HelloWorld.java
: 文件
HelloWorld.java
:
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( "Hello World" );
}
}
File myManifest
归档
myManifest
Main-Class: HelloWorld
Did the following at console: 在控制台执行以下操作:
javac HelloWorld.java
jar -cfm HelloWorld.jar myManifest HelloWorld.class
At the console I type: 在控制台上,键入:
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I get the expected output: Hello World
我得到了预期的输出:
Hello World
I make a simple bash script named "helloworld" 我制作了一个简单的bash脚本,名为“ helloworld”
#!/bin/bash
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I chmod +x helloworld
and then type ./helloworld
, I get the expected output: Hello World
我
chmod +x helloworld
,然后输入./helloworld
,我得到了预期的输出: Hello World
mkdir -p helloworld.app/Contents/MacOS
cp helloworld helloworld.app/Contents/MacOS
cp HelloWorld.jar helloworld.app/Contents/MacOS
open helloworld.app
I get the following error: 我收到以下错误:
LSOpenURLsWithRole() failed with error -10810 for the file /Users/josh/Desktop/helloworld/helloworld.app
/user/Josh/desktop/java-output.txt
appears, but has no text inside. /user/Josh/desktop/java-output.txt
出现,但里面没有文本。
As you can see, it appears that something is happening where running java inside an .app bundle is giving me that -10810 error. 如您所见,在.app捆绑包中运行Java时,似乎发生了某些事情,这给了我-10810错误。
Note: I also tried a variation of the first example, where I had the bash script launch /Applications/TextEdit.app, and that worked successfully. 注意:我还尝试了第一个示例的变体,在该示例中,我启动了bash脚本/Applications/TextEdit.app,并且运行成功。 It makes me suspect the problem is with java specifically.
这让我怀疑问题是专门针对Java的。
Does anyone have any idea what's causing this problem and how I can fix it? 有谁知道导致此问题的原因以及如何解决该问题?
I do not currently have an OS X machine handy to test this, but hints on the web from another question seem to imply that you need to set JAVA_HOME
and possibly PATH
in order to make java
work inside the app bundle. 我目前没有方便使用的OS X计算机来进行测试,但是另一个问题在网络上的提示似乎暗示您需要设置
JAVA_HOME
并可能设置PATH
才能使java
在App Bundle中工作。
Specifically, at the top of your shell script, before attempting to run your program, put the following lines, with appropriate changes for your system. 特别是,在外壳程序脚本的顶部,尝试运行程序之前,请放置以下几行,并对系统进行适当的更改。
export JAVA_HOME=/path/to/my/java/install
export PATH=$PATH:/path/to/directory/containing/java
More generally, to diagnose the root cause of the problem, change the existing line in your script to capture stderr
and see if that gives you any useful output that might have otherwise been swallowed by the app's environment. 更一般而言,要诊断问题的根本原因,请更改脚本中的现有行以捕获
stderr
然后查看该行是否为您提供了有用的输出,否则这些输出可能会被应用程序的环境所吞噬。
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt 2> /Users/josh/Desktop/java-error.txt
If you are able to capture the printed error, it may suffice to show you root cause. 如果您能够捕获打印的错误,则可能足以说明根本原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.