编辑:可以通过使用内置 jvm 参数创建可执行 jar 来避免上述所有问题。创建后,我可以使用 appbundle 将它捆绑到一个 .app 中。如何将 VM 参数集成到我的可执行 .jar 中?
我有一个可执行的 jar,我必须使用Oracle 的appbundler将其捆绑到一个 .app 中(以使其在 OS X 上运行)。如果我从终端使用java -XstartOnFirstThread -jar PhotoSelector.jar
. 由于 SWT(打包在我的可执行 jar 中)和 Cocoa 限制,我必须设置-XstartOnFirstThread
为 java 参数。问题是我不知道如何正确配置 Eclipse(Ant!)以将双击设置为 .app 将使用-XstartOnFirstThread
参数执行我的应用程序。这些是我的 XML 文件:
构建.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>
构建Mac.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>
所以,我的问题是:
- 双击时如何默认将-XstartOnFirstThread传递给.app?
- 我必须在 eclipse ant 工具中选择哪些目标才能正确导出我的 .app?
现在我的 .app 已创建,但它立即关闭。我使用 appbundler 因为 Jar Bundler 不支持 Java 1.7(在我的项目中广泛使用)。谢谢!