Consider:
When I create a simple Maven project in Eclipse I am getting this error:
web.xml is missing and
you need to add this tags to your pom.xml
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
Right click on the project --> New --> Other --> Standard Deployment Descriptor(web.xml)
then press Next it will create WEB-INF
folder with a web.xml
file inside.
That's it done.
You can do it also like this:
It will generate WEB-INF folder in src/main/webapp and an web.xml in it.
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
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>
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.)