Edit:可以通过创建带有内置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>
我的问题是:
- 如何通过-XstartOnFirstThread到。app默认双击时?
- 我必须在eclipse蚂蚁工具中选择哪些目标才能正确导出我的。app ?
现在我的。app被创建,但它立即关闭。我使用appbundler是因为Jar Bundler不支持Java 1.7(在我的项目中广泛使用)。谢谢你!
如何通过-XstartOnFirstThread到。app默认双击时?
在<bundleapp>
标签中添加以下内容:
<option value="-XstartOnFirstThread"/>
我必须在eclipse蚂蚁工具中选择哪些目标才能正确导出我的。app ?
我不确定你到底在问什么。大概是你的bundleapp
目标。请参考Jar Bundler文档获取分步指南。
注意Mac应用是一个扩展名为".app"的目录。在该目录内,你会发现目录/信息。plist文件。这将包含JVM参数和其他与Java相关的信息。如果你仍然有问题,这可能是一个开始调查的好地方(它也会帮助其他人回答你的问题)。