build.xml: No WEB-INF/web.xml file was added. – Apache Ant 1.7.1

Hi,
Recently I faced an issue with Apache Ant version 1.7.1.

I was building a WAR file using the standard dynamic web project in Eclipse Ganymede. It had “src” and “WebContent” directories as per the structure.

When I ran the target “create-war”  which looked like this.


<target name="create-war" depends="clean-dist">
<mkdir dir="${basedir}/dist"/>
<war destfile="${basedir}/dist/myapp.war" casesensitive="true">
<classes dir="${classes}" includes="**/*">
</classes>

<fileset dir="${basedir}/WebContent" casesensitive="yes">
<exclude name="META-INF/**"></exclude>
<exclude name="WEB-INF/**"></exclude>
</fileset>
<lib dir="${lib}"/>
<webinf  dir="${basedir}/WebContent/WEB-INF" casesensitive="true" >
<include name="web.xml"/>
<include name="struts-config.xml"/>
<include name="tiles-defs.xml"/>
</webinf>
<metainf dir="${basedir}/WebContent/META-INF" casesensitive="true"/>
</war>
</target>

This gave me the following error:

Buildfile: build.xml
clean-dist:
create-war:

BUILD FAILED
build.xml:65: No WEB-INF/web.xml file was added.
If this is your intent, set needxml=’false’
Total time: 2 seconds

I had web.xml file in appropriate directory to be picked up by target named “war”. But still keep getting this error.
I tried to fiddle with the attribute mentioned in the error “needxml” without any luck.

Finally I realized that I did not have “dist” directory created in my directory structure. Once I did that “create-war” ran successfully.

I wrote this one because the error that ANT throws, is surprisingly misleading and do not direct us to the actual cause of build failure.
It might be possible that you get similar error message on different use cases as well. This might be just one of it which can be fixed by creating the missing directory.

-Amit

Hi,

Recently I faced an issue with Apache Ant version 1.7.1.

I was building a WAR file using the standard dynamic web project in Eclipse Ganymede. It had “src” and “WebContent” directories as per the structure.

When I ran the target “create-war”  which looked like this.

Advertisements

2 Responses to build.xml: No WEB-INF/web.xml file was added. – Apache Ant 1.7.1

  1. Andriy says:

    Thank you very much. This is really tricky

  2. seohosting says:

    “Of course, what a great site and informative posts, I definitely will bookmark your blog.Have an awsome day!”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: