user1407668
user1407668

Reputation: 617

Jar File Not getting created with ant script

I am trying to execute an ant script which will compile, create the jar & execute. I am getting "Build successful" message. But the jar file is not getting created.

My ant file is :

<?xml version="1.0" encoding="UTF-8"?>
<project name="TestAnt" basedir="." default="compile">
    <description>simple example build file</description>
    <property name="src" location="src"/>
    <property name="output" location="bin"/>
    <property name="dist" location="."/>
    <target name="compile">
        <javac includeantruntime="false"  destdir="${output}">
            <src path="${src}"/>
    <!-- <classpath refid="java"/> -->
        </javac>
    </target>
    <target name="jar" depends="compile">
        <jar jarfile="${dist}/Test.jar" basedir="${output}">
            <manifest>
                <attribute name="Main-Class" value="Test"/>
            </manifest>
        </jar>
    </target>
    <target name="run">
        <java jar="${dist}/Test.jar" fork="true"/>
    </target>
</project>

Can anyone help please?

Upvotes: 0

Views: 2467

Answers (3)

kjp
kjp

Reputation: 3116

Change this line <project name="TestAnt" basedir="." default="compile"> to <project name="TestAnt" basedir="." default="jar">. This will both compile and create the jar - since compile target is a dependent on the jar task.

Upvotes: 2

nfechner
nfechner

Reputation: 17545

Are you sure, you are calling the correct target? Because your default target is compile, not jar, so if you supply no target, no jar file will be created.

Upvotes: 0

tofcoder
tofcoder

Reputation: 2382

How do you call you ant script? If you just run ant like that:

ant

It will only compiles your files, as this is the default target. To build the jar, you have to call the jar target:

ant jar

Upvotes: 1

Related Questions