簡體   English   中英

使用java for Mac OS X的Jar文件創建應用程序包?

[英]creating application bundle of with Jar files of java for Mac OS X?

我用Swing寫了一個小游戲程序,它被組織成包。 我一直在努力創建一個幾乎沒有任何成功的game.app 我正在關注此鏈接 ,我甚至無法通過第1步。

首先,我在頂級目錄中執行jar cvf HangManProject.jar *

  1. 在此之后,要創建build.xml ,我右鍵單擊項目文件夾並生成如下所示的ant文件。 你可以注意到我上一步中的HangManProject.jar 在此輸入圖像描述

  2. 完成此步驟后,我在我的頂級目錄(與HangManProject.jar相同的位置)上創建並提供了build.xml。

  3. 現在我嘗試了上面鏈接建議的ant jar來創建dist / HangManProject.jar。 但我收到以下錯誤消息:

    Buildfile:/Users/Tom/Documents/workspace/HangManProject/build.xml

    BUILD FAILED項目“HangManProject”中不存在目標“jar”。

從圖像中可以看出,HangManProject.jar存在於同一目錄中。 我不明白為什么會彈出這個錯誤。

我也嘗試過ant -verbose (實際上並不知道它的作用),並讓它成功地工作

build:

BUILD SUCCESSFUL
Total time: 2 seconds

我不知道ant -verbose是否有用,但我想在進入上面鏈接的下一步之前我必須讓ant jar工作(步驟3)。 請給我你的建議。

編輯:這是我的Eclipse自動生成的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="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文件中創建一個“target”來告訴ant如何創建jar(要包含哪些文件等)。

有關如何執行此操作的信息,請參閱此ant教程

但它看起來像這樣:

編輯:現在你粘貼了build.xml我添加了depends屬性。

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

    </jar>
</target>

雖然你必須要小心,但是build.xml說eclipse會自動生成這個文件,任何修改都會被覆蓋(我假設你改變了構建設置/類路徑等)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM