tags:

views:

59

answers:

3

Hello,

While executing mvn install, I'm getting following error:

Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executing in update mode)

My web application structure tree is like that:

my-app
|-- pom.xml
|-- src
    |-- ...
    |-- WebContent
        |-- ...
        |-- META-INF
        |-- WEB-INF
            |-- classes
                |-- ...
            |-- lib
            |-- **web.xml**

My POM file looks like that:

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>masters.traffic</groupId>
  <artifactId>traffic_web</artifactId>
  <packaging>war</packaging>
  <name>traffic_web</name>
  <version>0.1.0</version>
  <build>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>                    
                </configuration>
            </plugin>
        </plugins>
  </build>

    ...
</project>

How to properly fix that issue ?

Regards

A: 

Take a look at this comment:

http://stackoverflow.com/questions/1297473/maven-including-a-meta-inf-folder-in-the-classes-folder/1298573#1298573

I believe Maven expects a folder called "webapp", not "WebContent".

Ben J
+1  A: 

My guess is that maven-war-plugin is looking for src/main/webapp/WEB-INF/web.xml, but can't find it, and wants you to specify the (non-maven-standard) location explicitly. If you can't rename WebContent to webapp and move it under src/main/ (recommended), you could try adding something like this to your <build>

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webXml>${basedir}/src/WebContent/WEB-INF/web.xml</webXml>
    <warSourceDirectory>${basedir}/src/WebContent</warSourceDirectory>
  </configuration>
</plugin>
Lauri Lehtinen
+2  A: 

I strongly recommend to use Maven's standard layout:

  • put the Java sources in src/main/java (and remove the sourceDirectory element)
  • put the Web application sources in src/main/webapp
  • remove the classes and lib directories under WEB-INF

Sure, you can customize the layout but this is IMO more troubles and useless efforts than benefits. Just follow the conventions.

Pascal Thivent