154

Consider:

Enter image description here

When I create a simple Maven project in Eclipse I am getting this error:

web.xml is missing and <failOnMissingWebXml> is set to true

How can I fix this problem?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Yogesh Doke
  • 1,706
  • 2
  • 12
  • 20
  • 6
    You need to add the `maven-war-plugin`. This is an implicit plugin where the default value for that configuration property is true. You need to explicitly declare it and set the configuration property to false. See more [here](https://maven.apache.org/plugins/maven-war-plugin/). Or you can add an empty web.xml – Paul Samsotha Aug 05 '15 at 16:14

22 Answers22

414

This is a maven error. It says that it is expecting a web.xml file in your project because it is a web application, as indicated by <packaging>war</packaging>. However, for recent web applications a web.xml file is totally optional. Maven needs to catch up to this convention. Add this to your maven pom.xml to let maven catch up and you don't need to add a useless web.xml to your project:

<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>
</build>

This is a better solution than adding an empty web.xml because this way your final product stays clean, your are just changing your build parameters.

For more current versions of maven you can also use the shorter version:

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Martijn Burger
  • 7,315
  • 8
  • 54
  • 94
  • 29
    This answer is more logical than others. – smwikipedia Nov 23 '15 at 06:52
  • Add a missing step: you need to right click on `project -> Maven -> Update Project` to make this configuration come into effect. – smwikipedia Dec 06 '15 at 15:11
  • 7
    If you are using a in Servlet 3.0+ environment and have any implementation of a ``Interface WebApplicationInitializer`` this answer is the correct approach. It's the sensible way to solve this problem - no point adding the ``web.xml`` after taking steps to live without it! – Geeb Jan 29 '16 at 13:27
  • This answer is more logical than others – Shridutt Kothari Feb 29 '16 at 07:50
  • 4
    This is a better answer than creating an empty web.xml – dtortola Apr 14 '16 at 10:01
  • 1
    Works even without Maven > Update Project. So it isn't needed. – Lucky Apr 20 '16 at 10:58
  • 14
    Please consider updating your answer for a shorter configuration, as suggested [below](http://stackoverflow.com/a/35519476/859604). Including `false` suffices instead of the more verbose plugin configuration settings. – Olivier Cailloux Aug 10 '16 at 21:49
  • Thanks. I updated the answer, however this only works for more recent versions of maven. The first solution will always work. – Martijn Burger Aug 12 '16 at 08:27
  • 1
    @MartijnBurger I found that maven doc says default value of failOnMissingWebXml of maven-war-plugin is false, so why we need to set it false explicitly? http://maven.apache.org/plugins/maven-war-plugin/war-mojo.html – frank Oct 29 '16 at 14:56
  • 1
    @frank According to the docs that default is: `Starting with 3.1.0, this property defaults to false if the project depends on the Servlet 3.0 API or newer.` So for versions before 3.1.0 you need to set it explicitly. – Martijn Burger Jul 05 '17 at 12:39
  • false HELPED ME – Chinmoy Jun 28 '18 at 11:56
  • 1
    Starting with v3.1.0 of the plugin, this property defaults to false if the project depends on the Servlet 3.0 API or newer (see https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#failOnMissingWebXml). – Pino Feb 09 '22 at 17:30
199

You can do it also like this:

  1. Right click on Deployment Descriptor in Project Explorer.
  2. Select Generate Deployment Descriptor Stub.

It will generate WEB-INF folder in src/main/webapp and an web.xml in it.

enter image description here

Verhagen
  • 3,885
  • 26
  • 36
Wojciechu
  • 3,314
  • 2
  • 14
  • 10
  • 39
    I would not recommend adding boilerplate to the code, just because your build tool gives an error. – Martijn Burger Nov 12 '15 at 20:34
  • 1
    @MartijnBurger Can you enlighten us about the possible repercussions of the above hack and if possible also add some other alternatives? - would help novice programmers like me. Thanks. – Sendhilkumar Alalasundaram Mar 14 '16 at 13:27
  • 7
    See my answer below for an alternative. The solution above is not wrong, it is just that you should always strive to make your final product as clean as possible. With the solution above, your final product will end up with an unnecessary `web.xml` file. You should fix this problem in you build tool (i.e. maven) instead. – Martijn Burger Mar 17 '16 at 12:31
  • You may also refer : http://eggsylife.co.uk/2009/12/20/eclipse-galileo-cannot-nest-src-folder/ – Satyendra Apr 25 '16 at 15:14
  • this will add unnecessary file in your project and other thing is that web.xml approcah is old . if you want to remove this error then just force update the maven error will be gone – jitendra varshney Jan 29 '19 at 07:48
34

If you already have web.xml under /src/main/webapp/WEB-INF but you still get error "web.xml is missing and is set to true", you could check if you have included /src/main/webapp in your project source.

Here are the steps you can follow:

  1. You can check this by right clicking your project, and open its Properties dialogue, and then "Deployment Assembly", where you can add Folder /src/main/webapp. Save the setting, and then,
  2. Go to Eclipse menu Project -> Clean... and clean the project, and the error should go away.

(I verified this with Eclipse Mars)

Yuci
  • 27,235
  • 10
  • 114
  • 113
20

You can also do this which is less verbose

<properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
liam mooney
  • 301
  • 2
  • 3
  • The most elegant solution IMHO. See [doc](https://maven.apache.org/plugins/maven-war-plugin/war-mojo.html#failOnMissingWebXml) (and an old eclipse [bug](https://bugs.eclipse.org/bugs/show_bug.cgi?id=471622) which prevented this solution to work, now solved). – Olivier Cailloux Aug 10 '16 at 21:51
19

If you use Spring Tool Suite, option for Generate Deployment Descriptor Stub is moved under Java EE Tools, so you:

  1. Right click on your project
  2. Select Java EE Tools
  3. Select Generate Deployment Descriptor Stub option

This will create web.xml file inside src/main/webapp/WEB-INF/ folder, and of course remove error from Maven's pom.xml file.

enter image description here

milan.latinovic
  • 2,217
  • 1
  • 21
  • 26
16

I have the same problem. After studying and googling, I have resolved my problem:

Right click on the project folder, go to Java EE Tools, select Generate Deployment Descriptor Stub. This will create web.xml in the folder src/main/webapp/WEB-INF.

W3ap0nX
  • 98
  • 2
  • 8
Tung
  • 1,579
  • 4
  • 15
  • 32
11

Eclipse recognizes incorrect default webapp directory. Therefore we should set clearly it by maven-war-plugin.

<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-war-plugin</artifactId>
      <version>3.0.0</version>
      <configuration>
        <webappDirectory>src/main/webapp</webappDirectory>
      </configuration>
    </plugin>
  </plugins>
</build>

Once saving this setting, the error will never occour if removed it. (I cannot explain why.)

3

I had the same problem, even though I had 'src/main/webapp/WEB-INF/' folder with correct web.xml.

The problem disappeared after I recreated (maven->eclipse) configuration with Maven build.. I executed mvn eclipse:clean eclipse:eclipse

And then I used Maven -> Update Project to add (eclipse->maven) plugin specific options.

Boris Treukhov
  • 17,493
  • 9
  • 70
  • 91
2

I encountered this issue in eclipse only, everything worked fine in Maven command line, and my web.xml file existed. It was a mature project (already deployed out in production) that was impacted. My problem was tied to the eclipse metadata. There was an issue with one of the files in my .settings/ folder, specifically org.eclipse.wst.common.component had been changed. I was able to restore this file to its prior version, which resolved the issue in my case.

Note that Yuci's answer did not work for me, when I tried to click on Deployment Assembly in the eclipse properties, I got an error that said "the currently displayed page contains invalid values."

The Gilbert Arenas Dagger
  • 12,071
  • 13
  • 66
  • 80
  • I had the same situation and had to restore the org.eclipse.wst.common.component file from my .settings/ folder and my project works now, apparently the component's content was deleted, so it hasn't the path to my web.xml file. Also when I tried to open Deployment Assembly in the eclipse properties got the same error: "the currently displayed page contains invalid values." I found this answer a bit late but this's how I solve it. Great answer btw. – Jorge Valdés Aug 28 '17 at 12:06
2

For Project with web.xml present Project-->Properties-->Deployment Assembly,where you can add Folder src/main/webapp. Save change. Clean the project to get going.

For Project with web.xml not present Set failOnMissingWebXml to false in pom.xml under properties tag.

Saurav
  • 392
  • 4
  • 4
1

Do this:

Go and right click on Deployment Descriptor and click Generate Deployment Descriptor Stub.

1

you need to add this tags to your pom.xml

 <properties>
    <failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Meriem Bader
  • 112
  • 2
  • 15
1

Please add the following XML Code before the closing tag </ project > in POM.XML

            <properties>
                <failOnMissingWebXml>false</failOnMissingWebXml>
            </properties>

This should solve your error for the missing WEB.XML file.

0

It doesn't make sense to create a web.xml just elcipse wants it, even there is no need. This is the case if you have servlet conatiner embedded or living without xml cfg like spring-boot does. The you just diable JavaEE (useless stuff) in eclipse on project level or global

Eclipse/STS>Windows>Preferences>JavaEE>Doclet>Webdoclet> "uncheck" DeploymentDescriptor > OK
Dennis Kriechel
  • 3,719
  • 14
  • 40
  • 62
cforce
  • 13
  • 4
0

Remove files from -web/.setting&-admin/.setting

1

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
jun gao
  • 11
0

Select your project and select the "Deployment Descriptor" option and then choose "Generate Deployment Descriptor stub"

0

The step of : Select your project and select the "Deployment Descriptor" option and then choose "Generate Deployment Descriptor stub" works fine. The issue is that it is not always the case that we need web.xml, so it is best to append false to pom.xml

0

Right click on the project --> New --> Other --> Standard Deployment Descriptor(web.xml)

1

then press Next it will create WEB-INF folder with a web.xml file inside.

2

That's it done.

Hakan Dilek
  • 2,178
  • 2
  • 23
  • 35
0

My project had nothing to do with war, but the same error. I had to remove project from eclipse, delete all eclipse files from the project folder and reimport maven project.

user9999
  • 113
  • 2
  • 10
0

If you were using Eclipse, you can do this graphically as follows:

  1. Find "Overview" tab at the bottom of editor pane
  2. Open "Properties" line button
  3. Click Create... button on the right
  4. Input <Name, Value> pair
  5. Press OK enter image description here
Park JongBum
  • 1,245
  • 1
  • 16
  • 27
-1

Create WEB-INF folder in src/webapp, and include web.xml page inside the WEB-INF folder then

-1

Right click on the project, go to Maven -> Update Project... , then check the Force Update of Snapshots/Releases , then click Ok. It's done!

João V.
  • 61
  • 1
  • 12