编辑:通过创建一个内置jvm参数的可执行jar,可以避免上述所有问题。创建后,我可以使用appbundler将其捆绑到.app中。如何将VM参数集成到我的可执行文件.jar?
中我有一个可执行jar,我必须使用Oracle appbundler捆绑到.app中(以使其在OS X上运行)。如果我使用java -XstartOnFirstThread -jar PhotoSelector.jar
从终端启动它,我的jar在OS X上完美运行。由于SWT(在我的可执行jar中打包)和Cocoa限制,我必须将-XstartOnFirstThread
设置为java参数。问题是我不知道如何正确配置Eclipse(Ant!)来设置双击到.app将使用-XstartOnFirstThread
参数执行我的应用程序。这些是我的XML文件:
在build.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="build" name="PhotoSelector">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../eclipse Java"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<import file="buildMac.xml"/>
<path id="PhotoSelector.classpath">
<pathelement location="bin"/>
<pathelement location="lib/swt_64_OsX.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.java"/>
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="bin"/>
</target>
<target depends="clean" name="cleanall"/>
<target depends="build-subprojects,build-project" name="build"/>
<target name="build-subprojects"/>
<target depends="init" name="build-project">
<echo message="${ant.project.name}: ${ant.file}"/>
<javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
<src path="src"/>
<classpath refid="PhotoSelector.classpath"/>
</javac>
</target>
<target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
<target description="copy Eclipse compiler jars to ant lib directory" name="init-eclipse-compiler">
<copy todir="${ant.library.dir}">
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</copy>
<unzip dest="${ant.library.dir}">
<patternset includes="jdtCompilerAdapter.jar"/>
<fileset dir="${ECLIPSE_HOME}/plugins" includes="org.eclipse.jdt.core_*.jar"/>
</unzip>
</target>
<target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
<property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
<antcall target="build"/>
</target>
<target name="Main">
<java classname="com.selector.Main" failonerror="true" fork="yes">
<classpath refid="PhotoSelector.classpath"/>
</java>
</target>
</project>
BuildMac.xml
<?eclipse.ant.import?>
<project name="PhotoSelectorBundler">
<taskdef
name="bundleapp"
classname="com.oracle.appbundler.AppBundlerTask"
classpath="lib/appbundler-1.0.jar" />
<target name="bundle">
<bundleapp
outputdirectory="dist"
name="PhotoSelector"
displayname="Photo Selector"
identifier="com.selector.Main"
mainclassname="Main"
icon="src/com/selector/256.icns">
<classpath file="dist/PhotoSelector.jar" />
</bundleapp>
</target>
</project>
所以,我的问题是:
现在我的.app已创建,但会立即关闭。我使用appbundler因为Jar Bundler不支持Java 1.7(在我的项目中广泛使用)。谢谢!
答案 0 :(得分:3)
双击时如何默认将-XstartOnFirstThread传递给.app
在<bundleapp>
标记中添加以下内容:
<option value="-XstartOnFirstThread"/>
目标我必须在eclipse ant工具中选择正确导出我的.app吗?
我不确定你在这里问的确切。大概这将是你的bundleapp
目标。有关分步指南,请参阅Jar Bundler documentation。
请注意,Mac应用是扩展名为“.app”的目录。在该目录中,您将找到Contents / Info.plist文件。这将包含您的JVM args和其他Java相关信息。如果你继续遇到问题,这可能是一个开始调查的好地方(这也有助于其他人回答你的问题)。