Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot change version of project facet Dynamic Web Module to 2.5

I've inherited a Java web app from another company. I'm trying to load it into Eclipse (via Import Maven Project), and getting an error that says "Cannot change version of project facet Dynamic Web Module to 2.5".

I've been poking around a little, and one thing I'm finding is that the web.xml file starts with

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"     id="WebApp_ID" version="2.5"> 

and the pom.xml specifies a dependency of

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

but the .settings folder contains a file with this

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

and I suspect that the 3.0 specified here is conflicting with the 2.5 specified elsewhere. Is that likely to be the case? Is there any way this combination of settings could NOT result in errors? (Older version of Eclipse, eg?)

like image 683
joelt Avatar asked Aug 28 '14 14:08

joelt


People also ask

What is Dynamic Web Module version?

Dynamic Web Module version correlates with Servlet API version . Ideally a Servlet is an object that receives a request and generates a response based on that request. Take a look at below image from wikipedia, it's Servlet API history.

How do I fix the dynamic Web Project missing in Eclipse?

Step 1: Click Help -> Install New Software. Step 2: In Work with add http://download.eclipse.org/releases/oxygen. If you are using any other Eclipse product like Neon then replace oxygen with neon. Step 3: Now expand checkbox with name Web, XML, Java EE and OSGi Enterprise Development.


1 Answers

short version

Try this:

  • Deselect the Dynamic Web Module in your project facets. Right click the Project -> preferences -> Project Facets
  • Then run Maven -> Update Project again.

Long Version

I've had this problem a number of times while learning some eclipse dynamic web/spring stuff and none of the other solutions fixed my issue reliably or helped me understand what was causing the issue. I think I am beginning to.

So it appears that when you run a Maven -> Update Project, m2e (I assume) is ADDING the Dynamic Web Module to the Project Facets. Adding is the key word here. So when I went in and updated web.xml from [...] http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd" version="2.3"> to [...] http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

I got the error "Cannot change version of project facet Dynamic Web Module to 2.5."

Same was true for 3.0 when I tried that.

It appears m2e is capable of adding this to your project but like the error says it is unable to change it once it is set. So simply deselect it in the project facets page. Hit O.K. to save your preferences and run Maven Update again.

Eclipse Project Facets Dynamic Web Module

You shouldn't need to include javax.servlet in your pom.xml if you have a server (like tomcat) facet added.

Servlet-Api included in libraries

like image 81
TheSporkboy Avatar answered Sep 24 '22 12:09

TheSporkboy