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

EclipseMavenJakarta EeM2eclipse

Eclipse Problem Overview


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?

Eclipse Solutions


Solution 1 - Eclipse

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>

Solution 2 - Eclipse

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

Solution 3 - Eclipse

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)

Solution 4 - Eclipse

You can also do this which is less verbose

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

Solution 5 - Eclipse

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

Solution 6 - Eclipse

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.

Solution 7 - Eclipse

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.)

Solution 8 - Eclipse

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.

Solution 9 - Eclipse

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."

Solution 10 - Eclipse

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.

Solution 11 - Eclipse

Do this:

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

Solution 12 - Eclipse

you need to add this tags to your pom.xml

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

Solution 13 - Eclipse

Please add the following XML Code before the closing tag in POM.XML

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

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

Solution 14 - Eclipse

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

Solution 15 - Eclipse

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

1

Solution 16 - Eclipse

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

Solution 17 - Eclipse

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

Solution 18 - Eclipse

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.

Solution 19 - Eclipse

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.

Solution 20 - Eclipse

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

Solution 21 - Eclipse

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionYogesh DokeView Question on Stackoverflow
Solution 1 - EclipseMartijn BurgerView Answer on Stackoverflow
Solution 2 - EclipseWojciechuView Answer on Stackoverflow
Solution 3 - EclipseYuciView Answer on Stackoverflow
Solution 4 - Eclipseliam mooneyView Answer on Stackoverflow
Solution 5 - Eclipsemilan.latinovicView Answer on Stackoverflow
Solution 6 - EclipseTungView Answer on Stackoverflow
Solution 7 - EclipseDEWA Kazuyuki - 出羽和之View Answer on Stackoverflow
Solution 8 - EclipseBoris TreukhovView Answer on Stackoverflow
Solution 9 - EclipseThe Gilbert Arenas DaggerView Answer on Stackoverflow
Solution 10 - EclipseSauravView Answer on Stackoverflow
Solution 11 - EclipseNuno MarquesView Answer on Stackoverflow
Solution 12 - EclipseMeriem BaderView Answer on Stackoverflow
Solution 13 - EclipseSyed Aaqib HussainView Answer on Stackoverflow
Solution 14 - EclipsecforceView Answer on Stackoverflow
Solution 15 - Eclipsejun gaoView Answer on Stackoverflow
Solution 16 - EclipseChristina VimalaView Answer on Stackoverflow
Solution 17 - EclipseLotchi DagboView Answer on Stackoverflow
Solution 18 - EclipseVraj PatelView Answer on Stackoverflow
Solution 19 - Eclipseuser9999View Answer on Stackoverflow
Solution 20 - Eclipsebasavaraj MarapurView Answer on Stackoverflow
Solution 21 - EclipseJoão V.View Answer on Stackoverflow