10

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

5 Answers 5

19

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I've spent a lot of time figuring out why JSF wasn't rendering and I had WEB-INF in a different directory, then, fiddling with the IDEA .iml file I got it working by adding a deployment descriptor for the web.xml, what's weird is that this then stopped working.. I guess now it'll work for good ;)
14

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> 

2 Comments

What if i have no web.xml in my web appliction ?
@Vivek add <failOnMissingWebXml>false</failOnMissingWebXml> to configuration
1

Take a look at this comment:

Maven: Including a META-INF folder in the classes folder

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

Comments

0

I ran into this issue recently and the problem was that my resource class was not specifying an initial path at the top of the class. Each method specifed a path, but there was nothing specifying the initial path.

Example:

@Path("/") public class MyResource { @GET @Produces("text/html") public String foo() { return "foo"; } @GET @Path("pt") @Produces("text/html") public String bar() { return "bar"; } 

Will work just fine. But,

public class MyResource { @GET @Produces("text/html") public String foo() { return "foo"; } @GET @Path("pt") @Produces("text/html") public String bar() { return "bar"; } 

will not

Comments

0

If you're using eclispe, make sure to right click the project and create a Maven "project." You can compile as a batch from command line with updates using mvn generate:archetype -B -cpu but you might have to manually structure a few things. With this it will run as a web application or a client application. Add this code to pom.xml.

<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.6</version> <configuration> <failOnMissingWebXml>false</failOnMissingWebXml> </configuration> </plugin> </plugins> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.