savva
savva

Reputation: 155

Ant don't start war target

I have three targets in build.xml.

There are not errors in process.

First two runned successfully, but third don't start and there are not war file in result.

This is my buid.xml

<?xml version="1.0" encoding="utf-8"?>
<project name="LoginProject" basedir="." default="compile">

    <property name="src.dir"     value="src"/>
    <property name="classes.dir" value="build/classes"/>
    <property name="war.dir" value="build/war"/>

    <target name="clean">
        <delete dir="build"/>
    </target>

    <target name="compile" depends="clean">
        <mkdir dir="${classes.dir}"/>
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false">
            <classpath location="lib/myfaces-api-2.0.2.jar"/> 
            <classpath location="lib/servlet-api.jar"/> 
        </javac>
    </target>

    <target name="war" depends="compile">
        <mkdir dir="${war.dir}"/>
        <war destfile="${war.dir}/loginproject.war" webxml="web/WEB-INF/web.xml">
            <fileset dir="WebContent"/>
            <lib dir="lib"/>
            <classes dir="${classes.dir}"/>
        </war>
    </target>   
</project>

And this is log from command line

D:\Work\Java\AntLoginProject>ant
Buildfile: D:\Work\Java\AntLoginProject\build.xml

clean:
[delete] Deleting directory D:\Work\Java\AntLoginProject\build

compile:
    [mkdir] Created dir: D:\Work\Java\AntLoginProject\build\classes
    [javac] Compiling 3 source files to D:\Work\Java\AntLoginProject\build\classes

BUILD SUCCESSFUL
Total time: 1 second

What wrong i do?

I change default target to war. But now get error.

D:\Work\Java\AntLoginProject>ant war
Buildfile: D:\Work\Java\AntLoginProject\build.xml

BUILD FAILED
D:\Work\Java\AntLoginProject\build.xml:30: Content is not allowed in trailing section.

Total time: 0 seconds

Upvotes: 1

Views: 2084

Answers (2)

Mark O&#39;Connor
Mark O&#39;Connor

Reputation: 77951

Call the build as follows:

ant war

Alternatively change the default target from "compile" to "war"


Update:

The default target is changed as follows:

<?xml version="1.0" encoding="utf-8"?>
<project name="LoginProject" basedir="." default="war">
..

Upvotes: 4

dee-see
dee-see

Reputation: 24078

Your default target is compile and you only call ant. You need to specify ant targetName if you want to run a target that's not default. In your case: ant war.

Upvotes: 2

Related Questions