的.app"从OSX&QUOT运行Java;束的原因及QUOT;错误-10810" [英] Running Java from an OSX ".app" bundle causes "Error -10810"
问题描述
这是在OSX小牛通过虚拟盒测试,并在优胜美地在MacBook。
This was tested on OSX Mavericks through virtual box, and on Yosemite on a macbook.
我有一个名为的HelloWorld.jar的简单可执行的JAR。
I have a simple executable jar named "HelloWorld.jar".
我试图创建此Java应用程序建立的.app包。 (显然,我实际的程序比较复杂,但我又缩减到最起码的问题)。
I am trying to create a .app bundle for this java application. (Obviously, my actual program is more complex, but I have whittled it down to the barest problems).
在控制台I型
回声的Hello World(没有java)> /Users/josh/Desktop/test-output.txt
我查看测试-output.txt的和看到预期的输出。
I view test-output.txt and see the expected output.
我做一个名为一个简单的bash脚本测试
:
I make a simple bash script named test
:
#!/bin/bash
echo "Hello World (no java)" > /Users/josh/Desktop/test-output.txt
I 使用chmod + x检验
,然后键入 ./测试
,我认为测试output.txt的看预期的输出。
I chmod +x test
and then type ./test
, I view test-output.txt and see the expected output.
mkdir -p test.app/Contents/MacOS
cp test test.app/Contents/MacOS
open test.app
我查看测试-output.txt的和看到预期的输出。
I view test-output.txt and see the expected output.
文件 HelloWorld.java
:
public class HelloWorld {
public static void main ( String[] args ) {
System.out.println ( "Hello World" );
}
}
文件 myManifest
Main-Class: HelloWorld
在有没有控制台以下内容:
Did the following at console:
javac HelloWorld.java
jar -cfm HelloWorld.jar myManifest HelloWorld.class
步骤1 - 测试在控制台 - 作品
在控制台I型:
Java的罐子的HelloWorld.jar> /Users/josh/Desktop/java-output.txt
我得到预期的输出:的Hello World
我做一个名为一个简单的bash脚本的HelloWorld
I make a simple bash script named "helloworld"
#!/bin/bash
java -jar HelloWorld.jar > /Users/josh/Desktop/java-output.txt
I 搭配chmod + X的HelloWorld
,然后键入 ./的HelloWorld
,我得到预期的输出:的Hello World
I chmod +x helloworld
and then type ./helloworld
, I get the expected output: 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()失败,出现错误-10810该文件/Users/josh/Desktop/helloworld/helloworld.app </ code>
LSOpenURLsWithRole() failed with error -10810 for the file /Users/josh/Desktop/helloworld/helloworld.app
/user/Josh/desktop/java-output.txt
出现,但里面没有文字。
/user/Josh/desktop/java-output.txt
appears, but has no text inside.
正如你所看到的,看来事情正在发生凡的.app包内运行Java是给我-10810错误。
As you can see, it appears that something is happening where running java inside an .app bundle is giving me that -10810 error.
注:我也尝试了第一个例子,在那里我有bash脚本推出/Applications/TextEdit.app的变化,而成功的合作。这让我怀疑,问题是用java明确。
Note: I also tried a variation of the first example, where I had the bash script launch /Applications/TextEdit.app, and that worked successfully. It makes me suspect the problem is with java specifically.
没有人有任何想法什么导致这个问题,我怎么能解决这个问题?
Does anyone have any idea what's causing this problem and how I can fix it?
推荐答案
我目前还没有一个OS X的机器方便的测试,但是从<一个网络上的提示href=\"http://superuser.com/questions/682260/how-can-i-set-environment-variables-for-gui-apps-in-os-x-mavericks\">another问题似乎意味着你需要设置 JAVA_HOME
和可能 PATH
为了让<$ C应用程序捆绑在$ C>的Java 工作
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.
具体而言,在你的shell脚本的顶部,试图运行程序前,把下面的线,为您的系统相应的改变。
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.
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.
这篇关于的.app&QUOT;从OSX&QUOT运行Java;束的原因及QUOT;错误-10810&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!