0

I'm using Eclipse and I am getting the error "web.xml is missing and is set to true" in my pom.xml even though the web.xml isn't missing.

web.xml missing

In this thread it's suggested that we update Deployment Assembly in properties, but I can't do that because I get the following error:

deployment assembly error

I've also attempted to update the Maven build but I get an error when I try that.

What can I do to fix these issues?

Tiago Mussi
  • 801
  • 3
  • 13
  • 20

1 Answers1

0

This is an error from maven, it is saying that is expecting a web.xml file because the project is defined as a web project on pom.xml through <packaging>war</packaging>. As in some web application web.xml is optional, instead creating an empty web.xml you can overwrite the default value from the property failOnMissingWebXml on maven-war-plugin adding the following values on your pom.xml

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

If you need a web.xml file on your project, you can create it like this:

Maven WAR project default structure

web.xml content:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    <display-name>stackoverflow</display-name>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

To avoid some problems with IDE, try to run mvn clean install from prompt. If it works, you should check IDE files on the project (e.g. Eclipse has .project .setting and .classpath files who has some information that can be generating the error).

Tiago Mussi
  • 801
  • 3
  • 13
  • 20
  • 1
    A side note: since Maven WAR plugin 3.0.0, the default value for `failOnMissingWebXml` has been changed from true to false. See https://maven.apache.org/plugins/maven-war-plugin/ – Mincong Huang Jun 12 '18 at 08:52
  • The thing is I already have a web.xml in that location. So the issue is it's not seeing it, but I can't point it correctly because of the error I'm getting from the Deployment Assembly preference box. – Sophie Foreman Jun 12 '18 at 12:09
  • When you run 'mvn clean install' on a prompt, you get the same error? – Tiago Mussi Jun 12 '18 at 13:44
  • I haven't tried it from the command line but when I try to update the project in Maven in Eclipse I get "Updating Maven Project has encountered a problem" which is a null pointer exception but it doesn't tell me where – Sophie Foreman Jun 12 '18 at 13:54
  • Try to run 'mvn clean install' on a prompt. – Tiago Mussi Jun 12 '18 at 14:11
  • OK, so your problem is with your IDE, you are using Eclipse? – Tiago Mussi Jun 12 '18 at 14:13
  • Yes, using Eclipse Neon 4.6.3. I believe my main problem here is the error I get when trying to access Deployment Assembly. – Sophie Foreman Jun 12 '18 at 14:16
  • try to delete (create a backup) all configuration files and folders (.project and .settings) on the root of the project. Also .classpath (sometimes Eclipse can create it). – Tiago Mussi Jun 12 '18 at 14:19
  • Close the project on Eclipse, through System Explorer try to delete (create a backup) all configuration files and folders (.project and .settings) on the root of the project. Also .classpath (sometimes Eclipse can create it). And then open it on Eclipse and see if the errors persist... – Tiago Mussi Jun 12 '18 at 14:28