使用Mac OS X的java Jar文件创建应用程序包?
我已经用Swing编写了一个小游戏程序,它被组织成包。我一直在努力创建一个使用Mac OS X的java Jar文件创建应用程序包?,java,macos,bundle,executable-jar,Java,Macos,Bundle,Executable Jar,我已经用Swing编写了一个小游戏程序,它被组织成包。我一直在努力创建一个游戏.app,但几乎没有成功。我正在跟踪,甚至无法通过步骤1 首先,我在顶级目录中执行了jar cvf HangManProject.jar* 之后,为了创建build.xml,我右键单击项目文件夹并生成ant文件,如图所示。您可以注意到上一步中我的HangManProject.jar就在那里 在这一步之后,我创建了build.xml,并在我的顶级目录(与HangManProject.jar的位置相同)上可用 现在我按照上
游戏.app
,但几乎没有成功。我正在跟踪,甚至无法通过步骤1
首先,我在顶级目录中执行了jar cvf HangManProject.jar*
build.xml
,我右键单击项目文件夹并生成ant文件,如图所示。您可以注意到上一步中我的HangManProject.jar
就在那里antjar
,创建dist/HangManProject.jar。但我收到以下错误消息:
构建文件:/Users/Tom/Documents/workspace/HangManProject/build.xml
构建失败
目标“jar”在项目“HangManProject”中不存在ant-verbose
(实际上不知道它是做什么的),我让它成功地工作了
build:
BUILD SUCCESSFUL
Total time: 2 seconds
我不知道ant-verbose
在任何方面是否有帮助,但我想我必须让ant-jar
工作(步骤3),然后才能继续上面链接中的下一步。请给我你的建议
编辑:
这是我的build.xml
,它是由Eclipse自动生成的
<?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="HangManProject">
<property environment="env"/>
<property name="ECLIPSE_HOME" value="../../../Downloads/eclipse"/>
<property name="debuglevel" value="source,lines,vars"/>
<property name="target" value="1.7"/>
<property name="source" value="1.7"/>
<path id="JUnit 4.libraryclasspath">
<pathelement location="${ECLIPSE_HOME}/plugins/org.junit_4.11.0.v201303080030/junit.jar"/>
<pathelement location="${ECLIPSE_HOME}/plugins/org.hamcrest.core_1.3.0.v201303031735.jar"/>
</path>
<path id="HangManProject.classpath">
<pathelement location="bin"/>
<path refid="JUnit 4.libraryclasspath"/>
</path>
<target name="init">
<mkdir dir="bin"/>
<copy includeemptydirs="false" todir="bin">
<fileset dir="src">
<exclude name="**/*.launch"/>
<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="HangManProject.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>
</project>
您必须在build.xml文件中创建一个“目标”,告诉ant如何创建jar(要包含哪些文件等)
有关如何执行此操作的信息,请参见此
但它看起来是这样的:
编辑:既然粘贴了build.xml,我就添加了depends属性
<target name="jar" depends = "build">
<jar destfile="HangManProject.jar" >
<fileset dir="bin"/>
</jar>
</target>
尽管您必须小心,build.xml说eclipse自动生成此文件,任何修改都将被覆盖(我假设您更改了构建设置/类路径等)。您能发布build.xml吗?看起来它没有“罐子”target@dimoniy:我在上面的编辑中粘贴了build.xml我已经在上面粘贴了我的build.xml谢谢你的回复,现在我收到了这个错误
build FAILED/Users/Tom/Documents/workspace/HangManProject/build.xml:58:jar不支持“dependens”属性Total time:2秒
,谢谢,但是这本应该创建dist/HangManProject.jar,但是没有发生这样的事情。日志为“生成成功<代码>”。此链接http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html 指示将创建一个dist`目录。你能告诉我为什么没有发生这种情况吗?你必须告诉ant把罐子放在哪里。更改为
。不确定是否自动创建了dist dir,如果没有,则需要在创建新jar文件之前使用mkdir任务显式创建dir。