To do that, right-click the ServletInPlace project, select New→ File, click the Advanced button, check the “Link to file in the file system” checkbox, and click the Browse button. Browse to the webapps\ch11\WEB-INF directory, and click Open.
You can usually resolve these errors by updating Maven dependencies as follows: Right-click on your top-level project (not on the pom. xml file) in the Project Explorer view. From the menu, choose Maven > Update project.
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>
You can do it also like this:
It will generate WEB-INF folder in src/main/webapp and an web.xml in it.
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:
(I verified this with Eclipse Mars)
You can also do this which is less verbose
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
If you use Spring Tool Suite, option for Generate Deployment Descriptor Stub is moved under Java EE Tools, so you:
This will create web.xml file inside src/main/webapp/WEB-INF/ folder, and of course remove error from Maven's pom.xml file.
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
.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With