Question

I have written a small game program using Swing, which is organized into packages. I have been struggling to create a game.app with hardly any success. I am following This link and I could not even pass step 1.

first I did jar cvf HangManProject.jar * while on the top-level directory.

  1. After this, to create the build.xml, I right clicked the project folder and generated ant files as shown here. you can notice my HangManProject.jar sitting there from previous step.enter image description here

  2. After this step, I have build.xml created and available on my top-level directory (same location as HangManProject.jar).

  3. Now I tried ant jar as suggested by above link to create dist/HangManProject.jar. but I get the below error message:

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

    BUILD FAILED Target "jar" does not exist in the project "HangManProject".

As you can see from the image, the HangManProject.jar exist in the same directory. I do not understand why this error pops up.

I also tried ant -verbose (without actually knowing what it does) and I get it to work successful

build:

BUILD SUCCESSFUL
Total time: 2 seconds

I dont know if ant -verbose is helpful in anyway, but I guess I have to get ant jar working (step 3) before I proceed to next step in the link above. kindly give me your suggestions.

EDIT: Here is my build.xml that was autogenerated by 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>
Was it helpful?

Solution

You have to create a "target" in the build.xml file to tell ant how to create the jar (what files to include etc).

See this ant tutorial for information on how to do that.

but it will look something like this:

EDIT: now that you pasted your build.xml I added the depends attribute.

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

    </jar>
</target>

Although you have to be careful, the build.xml says that eclipse autogenerates this file and any modifications will be overwritten (I assume if you ever change build settings/classpath etc).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top