Dynamic Web Module 3.0 -- 3.1

EclipseSpringMavenSpring Mvc

Eclipse Problem Overview


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>

Eclipse Solutions


Solution 1 - Eclipse

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.

Solution 2 - Eclipse

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>

Solution 3 - Eclipse

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.

Solution 4 - Eclipse

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.

Solution 5 - Eclipse

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

Solution 6 - Eclipse

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.

Solution 7 - Eclipse

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.

Solution 8 - Eclipse

  1. Go to your project and find ".settings" directory [this one][1]
  2. Open file xml named:
    org.eclipse.wst.common.project.facet.core.xml
<?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)

  1. 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/

  2. Go to pom.xml file and paste these lines:

    YOUR_PROJECT_NAME org.apache.maven.plugins maven-compiler-plugin 3.3 1.8 THIS IS YOUR USING JDK's VERSION 1.8 SAME AS ABOVE
    [1]: https://i.stack.imgur.com/HwRjt.png

Solution 9 - Eclipse

  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"

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
Questiondu-itView Question on Stackoverflow
Solution 1 - EclipsedimoniyView Answer on Stackoverflow
Solution 2 - EclipseAlexey GrigorevView Answer on Stackoverflow
Solution 3 - EclipseNlp TrinhView Answer on Stackoverflow
Solution 4 - EclipseDirk SchumacherView Answer on Stackoverflow
Solution 5 - EclipseCamelTMView Answer on Stackoverflow
Solution 6 - EclipseDonatello BoccafornoView Answer on Stackoverflow
Solution 7 - EclipseAfshin GhaziView Answer on Stackoverflow
Solution 8 - EclipseLong TranView Answer on Stackoverflow
Solution 9 - EclipsePrakash BMView Answer on Stackoverflow