有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

macos使用Mac OS X的java Jar文件创建应用程序包?

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

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

  1. 之后,为了创建build.xml,我右键单击项目文件夹并生成ant文件,如图所示。你可以注意到我的HangManProject.jar坐在前面的步骤中enter image description here

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

  3. 现在我试着按照上面链接的建议创建dist/HangManProject。罐子但我得到以下错误信息:

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

    构建失败 目标“jar”在项目“Hangman project”中不存在

正如你从图片中看到的,刽子手计划。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>

共 (1) 个答案

  1. # 1 楼答案

    你必须在构建中创建一个“目标”。xml文件,告诉ant如何创建jar(包括哪些文件等)

    有关如何做到这一点的信息,请参见此ant tutorial

    但它看起来是这样的:

    编辑:现在你已经粘贴了你的构建。xml我添加了depends属性

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

    尽管你必须小心,但它的构造。xml表示eclipse自动生成这个文件,任何修改都将被覆盖(我假设如果您更改构建设置/类路径等)