【问题标题】:creating application bundle of with Jar files of java for Mac OS X?使用 Java 的 Jar 文件为 Mac OS X 创建应用程序包?
【发布时间】:2013-12-05 18:59:23
【问题描述】:

我使用 Swing 编写了一个小游戏程序,它被组织成包。我一直在努力创建game.app,但几乎没有成功。我正在关注This link,但我什至无法通过第 1 步。

首先我在顶级目录中执行jar cvf HangManProject.jar *

  1. 在此之后,为了创建build.xml,我右键单击项目文件夹并生成 ant 文件,如下所示。你可以注意到我的HangManProject.jar 从上一步坐在那里。

  2. 在这一步之后,我创建了 build.xml,并在我的顶级目录(与 HangManProject.jar 相同的位置)上可用。

  3. 现在我按照上面链接的建议尝试了ant jar 来创建 dist/HangManProject.jar。但我收到以下错误消息:

    构建文件:/Users/Tom/Documents/workspace/HangManProject/build.xml

    构建失败 项目“HangManProject”中不存在目标“jar”。

从图中可以看出,HangManProject.jar 存在于同一目录中。我不明白为什么会弹出这个错误。

我也尝试了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 吗?看起来它没有“jar”目标
  • @dimoniy:我在上面的编辑中粘贴了 build.xml

标签: java macos bundle executable-jar


【解决方案1】:

您必须在 build.xml 文件中创建一个“目标”来告诉 ant 如何创建 jar(要包含哪些文件等)。

请参阅此ant tutorial,了解如何执行此操作。

但它看起来像这样:

编辑:既然您粘贴了 build.xml,我添加了依赖属性。

<target name="jar" depends = "build">
    <jar destfile="HangManProject.jar" >
        <fileset dir="bin"/>    

    </jar>
</target>

尽管您必须小心,但 build.xml 表示 eclipse 会自动生成此文件,并且任何修改都将被覆盖(我假设您曾经更改构建设置/类路径等)。

【讨论】:

  • 我在上面粘贴了我的 build.xml
  • 感谢您的回复,现在我收到此错误BUILD FAILED /Users/Tom/Documents/workspace/HangManProject/build.xml:58: jar doesn't support the "depends" attribute Total time: 2 seconds
  • 这行得通,谢谢,但这应该创建 dist/HangManProject.jar 但没有发生这样的事情。日志是'BUILD SUCCESSFUL. This link http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html indicates a dist`目录将被创建..你能告诉我为什么这没有发生吗?
  • 你必须告诉蚂蚁把罐子放在哪里。更改为&lt;jar destfile = "dist/HangManProject.jar"&gt;。不确定是否自动创建 dist 目录,如果没有,需要在创建新的 jar 文件之前使用 mkdir 任务显式创建目录。
猜你喜欢
  • 1970-01-01
  • 2011-11-07
  • 1970-01-01
  • 1970-01-01
  • 2018-01-24
  • 2012-06-17
  • 2013-01-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多