Java 无法将项目方面动态 Web 模块的版本更改为 2.5

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25551213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 00:38:25  来源:igfitidea点击:

Cannot change version of project facet Dynamic Web Module to 2.5

javaeclipsemavenweb-applications

提问by joelt

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".

我从另一家公司继承了一个 Java Web 应用程序。我正在尝试将其加载到 Eclipse(通过导入 Maven 项目)中,并收到一条错误消息,提示“无法将项目方面动态 Web 模块的版本更改为 2.5”。

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

我一直在闲逛,我发现的一件事是 web.xml 文件以

<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

并且 pom.xml 指定了一个依赖项

    <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

但 .settings 文件夹包含一个文件

<?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?)

我怀疑这里指定的 3.0 与其他地方指定的 2.5 冲突。有可能是这种情况吗?有没有办法这种设置组合不会导致错误?(旧版本的 Eclipse,例如?)

回答by Harald Wellmann

My guess is the original authors manually changed the Project Facets of the Eclipse project after the initial import and never ran Maven | Updateafter that.

我的猜测是原作者在初始导入后手动更改了 Eclipse 项目的 Project Facets 并且从未运行过Maven | 在那之后更新

Anyway, for Maven projects, it's good practice not to commit any Eclipse metadata (i.e. .classpath, .project, .settings/) to SCM and to let m2e generate them on import.

无论如何,对于 Maven 项目,最好不要将任何 Eclipse 元数据(即.classpath, .project, .settings/)提交给 SCM 并让 m2e 在导入时生成它们。

So I'd recommend to copy your project structure, delete all Eclipse metadata from the copy and then import via m2e.

因此,我建议复制您的项目结构,从副本中删除所有 Eclipse 元数据,然后通过 m2e 导入。

If there are still any errors on import, than at least you might get a hint where the original authors tweaked the defaults, so you'll know where to start cleaning up.

如果导入时仍然存在任何错误,那么至少您可能会得到原始作者调整默认值的提示,因此您将知道从哪里开始清理。

回答by TheSporkboy

short version

精简版

Try this:

尝试这个:

  • Deselect the Dynamic Web Module in your project facets. Right click the Project -> preferences -> Project Facets
  • Then run Maven -> Update Projectagain.
  • 在您的项目构面中取消选择动态 Web 模块。 右键单击项目 -> 首选项 -> 项目构面
  • 然后再次运行Maven -> 更新项目

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.

我在学习一些 eclipse 动态 web/spring 的东西时遇到过这个问题很多次,其他解决方案都没有可靠地解决我的问题或帮助我了解导致问题的原因。我想我开始了。

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">

因此,当您运行Maven -> Update Project 时,m2e(我假设)似乎正在将动态 Web 模块添加到项目方面。添加是这里的关键词。因此,当我进入并更新 web.xml 从 [...] http://java.sun.com/xml/ns/javaee/web-app_2_3.xsd" version="2.3"> 到 [...] 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."

我收到错误消息“无法将项目方面动态 Web 模块的版本更改为 2.5”。

Same was true for 3.0 when I tried that.

当我尝试这样做时,3.0 也是如此。

It appears m2e is capable of adding this to your project but like the error says it is unable to changeit 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.

看起来 m2e 能够将它添加到您的项目中,但就像错误所说的那样,一旦设置就无法更改它。所以只需在项目方面页面中取消选择它。点击 OK 保存您的首选项并再次运行 Maven Update。

Eclipse Project Facets Dynamic Web Module

Eclipse Project Facets 动态 Web 模块

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

不应该需要包括在你的pom.xml的javax.servlet,如果你有一台服务器(如Tomcat)方面加入。

Servlet-Api included in libraries

库中包含的 Servlet-Api

回答by Gere

My solution was:

我的解决方案是:

Change header in my web.xml:

在我的 web.xml 中更改标题:

I put:

我放:

<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">
    <display-name>Servlet 3.0 Web Application</display-name>
</web-app>

and then just Maven -> Update Project

然后只是 Maven -> 更新项目

回答by HymanDev

See Cannot change version of project facet Dynamic Web Module to 3.0?

请参阅无法将项目方面动态 Web 模块的版本更改为 3.0?

Close the project, and directly update file 'org.eclipse.wst.common.project.facet.core.xml' located in the .settings folder of the project.

关闭项目,直接更新项目.settings文件夹下的'org.eclipse.wst.common.project.facet.core.xml'文件。

回答by Hatem Badawi

Open the Navigator view (Window > Show View > Other > General) and find that there is a .settings folder under your project, expand it and then open the file “org.eclipse.wst.common.project.facet.core.xml”, make the below changes and save the file.

打开 Navigator 视图(Window > Show View > Other > General),发现你的项目下有一个 .settings 文件夹,展开它然后打开文件“org.eclipse.wst.common.project.facet.core.xml ”,进行以下更改并保存文件。

Change the dynamic web module version in this line to 2.5 – <installed facet=”jst.web” version=”2.4″/>

将此行中的动态 web 模块版本更改为 2.5 – <installed facet=”jst.web” version=”2.4″/>

Change the JSF version in this line to 2.0 – <installed facet=”jst.jsf” version=”1.1″/>

将此行中的 JSF 版本更改为 2.0 – <installed facet=”jst.jsf” version=”1.1″/>

Change the Java version in this line to 1.5 or higher – <installed facet=”java” version=”1.5″/>.

将此行中的 Java 版本更改为 1.5 或更高版本 – <installed facet=”java” version=”1.5″/>.

After this changes you can change the version of Project facet Dynamic Web Module from the project properties; without giving you this warrning

更改后,您可以从项目属性更改项目方面动态 Web 模块的版本;没有给你这个警告

回答by CygiCoderJavaLerner

In my case I wanted to change dynamic facet form 2.3 to 3.1.

就我而言,我想将动态方面从 2.3 更改为 3.1。

What help me was one number change in may web.xml

对我有帮助的是 May web.xml 中的一个数字更改

From :

从 :

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app  > 
  <display-name>Archetype Created Web Application</display-name>
</web-app>

TO :

到 :

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_5.dtd" >

<web-app  > 
  <display-name>Archetype Created Web Application</display-name>
</web-app>

And then go to properties -> Project Facets -> Uncheck the Dynamic Web Module -> OK

然后转到属性 -> 项目构面 -> 取消选中动态 Web 模块 -> 确定

Updated Maven project.

更新了 Maven 项目。

回答by Mike V.C.

Note that current schema location for web-app is:

请注意,网络应用程序的当前架构位置是:

xsi:schemaLocation="http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/web-app_3_0.xsd"

回答by AlexH

@TheSporkboy is almost correct. I ran into this today and after some fiddling with configuration the solution was as follows:

@TheSporkboy 几乎是正确的。我今天遇到了这个问题,在对配置进行了一些摆弄之后,解决方案如下:

1- Change the setting for Dynamic Web Module in the Project Facets to latest 3.1

1- 将 Project Facets 中的 Dynamic Web Module 设置更改为最新的 3.1

2- Open up the project's web.xml from .../web-app_2_5.xsd to .../web-app_3_1.xsd

2- 打开项目的 web.xml 从 .../web-app_2_5.xsd 到 .../web-app_3_1.xsd

3- Update Maven project

3- 更新 Maven 项目

回答by user1419243

This blog post helped me very well: How to fix Cannot change version of project facet Dynamic Web Module to 3.0 Error in Eclipse.

这篇博文对我帮助很大: How to fix Cannot change version of project facet Dynamic Web Module to 3.0 Error in Eclipse

This post explains that if right click> properties> project facets> changing the version of Dynamic Web Moduleto the correct one does not help, try the following: right click> properties> resources> go to the address you see in locationpart. Open the org.eclipse.wst.common.project.facet.corefile and change the jst.webversion as you need. Refresh the project. It should work :)

这篇文章解释了如果右键单击>属性>项目方面>将版本更改为Dynamic Web Module正确的版本没有帮助,请尝试以下操作:右键单击>属性>资源>转到您看到的地址location部分。打开org.eclipse.wst.common.project.facet.core文件并jst.web根据需要更改版本。刷新项目。它应该工作:)

回答by jirou

you must change both files!

您必须更改这两个文件!

First step: close eclipse

第一步:关闭eclipse

Second step: change facet label "jst.web" in org.eclipse.wst.common.project.facet.core.xml

第二步:更改 org.eclipse.wst.common.project.facet.core.xml 中的 facet 标签“jst.web”

And finally, change the version of xsd in web.xml

最后,更改 web.xml 中 xsd 的版本

It works to me

它对我有用