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

December 24, 2009

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