问题描述
我一直在使用将Java应用程序打包为.app。如果我在.app包中包装JRE7,我已设法运行该应用程序。
是否可以配置.app(在Info.plist中)指向JAVA_HOME环境变量定义的JRE?
如果我这样做,我得到无法加载Java运行时环境!我试图以不同的方式配置JAVA_HOME,但没有成功!
I have been using Java Application Bundler to pack a Java application as .app. I have managed to run the application if I pack the JRE7 inside of the .app bundle.Is it possible to configure .app (in Info.plist) to point to the JRE defined by JAVA_HOME environment variable?If I do that, I am getting "Unable to load Java Runtime Environment"! I have tried to configure the JAVA_HOME in different ways, but with no success!
任何人都可以提供任何帮助或建议吗?
Can anyone provide any help or suggestion?
推荐答案
appbundler
应用程序可以使用应用程序包中的嵌入式Java 7 JRE,也可以使用中安装的Java 7 JRE code> / Library / Internet Plug-Ins / JavaAppletPlugin.plugin / Contents / Home (与Web浏览器插件使用的相同)。他们不能使用 / Library / Java / JavaVirtualMachines
下安装的 JDK (或其他任何地方),他们绝对不能使用Java 6.
appbundler
applications can use either an embedded Java 7 JRE inside the app bundle, or the Java 7 JRE installed in /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
(the same one used by the web browser plugin). They can't use a JDK installed under /Library/Java/JavaVirtualMachines
(or anywhere else, for that matter) and they definitely can't use Java 6.
而是手动构建bundle,主可执行文件是一个shell脚本,它运行 JAVA_HOME java
命令行工具>(如果未设置 JAVA_HOME
,可能会回退到 / Library / Internet Plug-Ins
JRE)。这样的脚本将能够支持Java 6和7。
What you can do, however, is not use appbundler
and instead build the bundle by hand, with the main executable being a shell script that runs the java
command line tool from JAVA_HOME
(maybe falling back to the /Library/Internet Plug-Ins
JRE if JAVA_HOME
is not set). Such a script will be able to support both Java 6 and 7.
您可以使用类似这样的内容 YourApp.app/Contents/MacOS/ YourApp
:
You would use something like this as YourApp.app/Contents/MacOS/YourApp
:
#!/bin/sh
PRG=$0
while [ -h "$PRG" ]; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
progdir=`dirname "$PRG"`
if [ -n "$JAVA_HOME" ]; then
JAVACMD="$JAVA_HOME/bin/java"
elif [ -x /usr/libexec/java_home ]; then
JAVACMD="`/usr/libexec/java_home`/bin/java"
else
JAVACMD="/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java"
fi
exec "$JAVACMD" -classpath "$progdir/../Resources/Jars/*" \
-Dapple.laf.useScreenMenuBar=true \
my.pkg.MainClass
然后将应用程序的JAR文件放在<$ c中$ c> YourApp.app/Contents/Resources/Jars , YourApp.app/Contents/Resources/icon.icns
中的图标,以及以下 YourApp.app/Contents/Info.plist
:
Then put your application's JAR files in YourApp.app/Contents/Resources/Jars
, the icon in YourApp.app/Contents/Resources/icon.icns
, and the following in YourApp.app/Contents/Info.plist
:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>YourApp</string><!-- relative to Contents/MacOS -->
<key>CFBundleGetInfoString</key>
<string>My clever application</string>
<key>CFBundleIconFile</key>
<string>icon.icns</string><!-- relative to Contents/Resources -->
<key>CFBundleInfoDictionaryVersion</key>
<string>8.0</string>
<key>CFBundleName</key>
<string>YourApp</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>8.0</string>
</dict>
</plist>
参见获取完整的详细信息,但请注意,这是一个稍微复杂的情况,因为 .app
脚本委托给另一个脚本,该脚本又从 .app
包之外的位置加载JAR文件。但原则仍然相同。
See the GATE Developer launcher for full details, though note that this is a slightly more convoluted case as the .app
script delegates to another script, which in turn loads the JAR files from a location that is outside the .app
bundle. The principle remains the same however.
这篇关于指向JAVA_HOME定义的JRE的Java AppBundler应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!