50

I have a mavenized codebased configured Spring 3.2.4 web app. When I build the app with Maven/pom.xml first I got an error that web.xml is missing. first I tried to create an empty web.xml. this was the moment when The project facets changed (and I don't know why). It switched from dynamic Web Module 3.0 to 3.1 and this is irreversible. How can I change it again into Dynamic Web Modules 3.0???

enter image description here

Additionally I can't remove the JAX-RS. Trying this it results in:

Failed while uninstalling JAX-RS (REST Web Services) 1.0.
org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp

Later I found out that I can avoid the Maven compile error by inserting the according plugin into pom.xml:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>
dimoniy
  • 5,820
  • 2
  • 24
  • 22
du-it
  • 2,561
  • 8
  • 42
  • 80

9 Answers9

72

I had similar troubles in eclipse and the only way to fix it for me was to

  • Remove the web module
  • Apply
  • Change the module version
  • Add the module
  • Configure (Further configuration available link at the bottom of the dialog)
  • Apply

Just make sure you configure the web module before applying it as by default it will look for your web files in /WebContent/ and this is not what Maven project structure should be.

EDIT:

Here is a second way in case nothing else helps

  • Exit eclipse, go to your project in the file system, then to .settings folder.
  • Open the org.eclipse.wst.common.project.facet.core.xml , make backup, and remove the web module entry.
  • You can also modify the web module version there, but again, no guarantees.
dimoniy
  • 5,820
  • 2
  • 24
  • 22
  • Do you mean removing the Dynamic Web Module in the Project Facets? I am not allowed to do that. Eclipse says that it cannot be removed. – du-it Oct 29 '13 at 16:15
  • 3
    @user233552 Well, then you have to do it the hard way... Exit eclipse, go to your project in the file system, then to .settings forlder. Open the org.eclipse.wst.common.project.facet.core.xml and remove the web module entry. Make file backup as it's likely to break things. You can also modify the version there, I'm not sure if it'll work though... – dimoniy Oct 29 '13 at 16:53
  • 1
    +1 for the second solution. I modified the module entry. – aboger Jun 10 '14 at 17:34
  • The first solution worked, but why is such a weird approch required?? – Jakob Alexander Eichler May 06 '16 at 16:28
62

If you want to use version 3.1 you need to use the following schema:

  • http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd

Note that 3.0 and 3.1 are different: in 3.1 there's no Sun mentioned, so simply changing 3_0.xsd to 3_1.xsd won't work.

This is how it should look like:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee" 
         xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">

</web-app>

Also, make sure you're depending on the latest versions in your pom.xml. That is,

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        ...
    </configuration>
</plugin>

and

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

Finally, you should compile with Java 7 or 8:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.3</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>
Alexey Grigorev
  • 2,415
  • 28
  • 47
  • 2
    This is the actual solution to have a clean maven project (without those .settings and other eclipse rubbish around) that people with eclipse are still able to open correctly. Also works with javax:javaee-api dependency. – Lorenzo Boccaccia Oct 06 '14 at 15:54
  • Changing the web-app schema references in my web.xml file (and telling Eclipse to update the Maven project) did the trick. – Chris Mar 18 '15 at 21:29
  • 2
    This answer should be marked as the correct solution, as it is. Clean and straight maven based! – Tom Fink May 18 '15 at 15:12
  • This doesn't answer the original question, how to revert to 3.0, but instead suggests a way for upgrading to 3.1. – Javier Villa May 26 '15 at 22:45
  • 2
    Note that the current maven-war-plugin version is 2.6 and that of maven-compiler-plugin is 3.3 (and you don't need to `groupId`). Also, you should add ` `. And then, you should use two URIs in `xsi:schemaLocation`: just change the `" xmlns:web="` part to a single space. – Marcel Korpel Aug 01 '15 at 23:58
  • For java 1.8 use version 3.5.1 of maven-compiler-plugin. I've spent 3 hrs trying to make it work with 1.8 with 3.3 and nothing seemed to change. For most recent version check http://mvnrepository.com/artifact/org.apache.maven.plugins/maven-compiler-plugin – Ghandhikus Feb 17 '16 at 17:33
  • (Just in case) @MarcelKorpel meant this : ` ... ` – nacho4d Mar 23 '16 at 15:47
10

I had the same problem and fixed this by editing org.eclipse.wst.common.project.facet.core.xml.

In this file, I was able to change the following line

<installed facet="jst.web" version="3.1"/>

back to

<installed facet="jst.web" version="3.0"/>

That seemed to fix the problem for me.

Nlp Trinh
  • 101
  • 1
  • 3
3

I was running on Win7, Tomcat7 with maven-pom setup on Eclipse Mars with maven project enabled. On a NOT running server I only had to change from 3.1 to 3.0 on this screen: enter image description here

For me it was important to have Dynamic Web Module disabled! Then change the version and then enable Dynamic Web Module again.

Dirk Schumacher
  • 1,479
  • 19
  • 37
2

Open Eclipse project properties, in Project Facets unselect "Dynamic Web Module",... Click OK Maven -> Update project

CamelTM
  • 1,225
  • 12
  • 17
1

In a specific case the issue is due to the maven-archetype-webapp which is released for a dynamic webapp, faceted to the ver.2.5 (see the produced web.xml and the related xsd) and it's related to eclipse. When you try to change the project facet to dynamic webapp > 2.5 the src folder structure will syntactically change (the 2.5 is different from 3.1), but not fisically.

This is why you will face in a null pointer exception if you apply to the changes.

To solve it you have to set from the project facets configuration the Default configuration. Apply the changes, then going into the Java Build Path you have to remove the /src folder and create the /src/main/java folder at least (it's also required /src/main/resources and /src/test/java to be compliant) re-change into the required configuration you desire (3.0, 3.1) and then do apply.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
0

I opened the project org.eclipse.wst.common.project.facet.core.xml and first changed then removed line with web module tag. Cleaned project and launched on Tomcat each time but it still didn't run. Returned line (as was) and cleaned project. Opened Tomcat settings in Eclipse and manually added project to Tomcat startup (Right click + Add and Remove). Clicked on project and selected Run on server....and everything was fine.

Afshin Ghazi
  • 2,784
  • 4
  • 23
  • 37
0

1) Go to your project and find ".settings" directory this one
2) Open file xml named:
org.eclipse.wst.common.project.facet.core.xml
3)

<?xml version="1.0" encoding="UTF-8"?>
    <faceted-project>
    <fixed facet="wst.jsdt.web"/>
    <installed facet="java" version="1.5"/>
    <installed facet="jst.web" version="2.3"/>
    <installed facet="wst.jsdt.web" version="1.0"/>
 </faceted-project>

Change jst.web version to 3.0 and java version to 1.7 or 1.8 (base on your current using jdk version)

4) Change your web.xml file under WEB-INF directory , please refer to this article:
https://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/
5) Go to pom.xml file and paste these lines:

<build>
    <finalName>YOUR_PROJECT_NAME</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source> THIS IS YOUR USING JDK's VERSION
                <target>1.8</target> SAME AS ABOVE
            </configuration>
        </plugin>
    </plugins>
</build>  
Long Tran
  • 73
  • 3
  • 5
0
  1. Go to Workspace location
  2. select your project folder
  3. .setting folder
  4. edit "org.eclipse.wst.common.project.facet.core"
  5. change installed facet="jst.web" version="3.0"