Eclipse 不可逆动态 Web 模块 4.0 选择;Tomcat 9 不支持

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48649041/
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-09-19 23:32:03  来源:igfitidea点击:

Eclipse irreversible Dynamic Web Module 4.0 selection; Tomcat 9 doesn't support it

javaeclipsetomcatjakarta-eetomcat9

提问by Garret Wilson

I'm using Eclipse Oxygen.2 (4.7.2) on Windows 10 with Java 8. I have a faceted project I run inside Eclipse using Tomcat. I had been using Tomcat 8.5, but on a new system I upgraded to Tomcat 9. Of course I removed the Tomcat 8.5 server and server runtime within Eclipse, and added back a Tomcat 9 server runtime.

我在带有 Java 8 的 Windows 10 上使用 Eclipse Oxygen.2 (4.7.2)。我有一个使用 Tomcat 在 Eclipse 中运行的分面项目。我一直在使用 Tomcat 8.5,但在新系统上我升级到了 Tomcat 9。当然,我在 Eclipse 中删除了 Tomcat 8.5 服务器和服务器运行时,并重新添加了 Tomcat 9 服务器运行时。

Before adding the Tomcat 9 server within Eclipse I verified the Project Facets of my project. I saw that Dynamic Web Module was set to "3.1", but that now "4.0" was available. I changed to "4.0", figuring this would give me access to newer APIs.

在 Eclipse 中添加 Tomcat 9 服务器之前,我验证了我的项目的 Project Facets。我看到动态 Web 模块设置为“3.1”,但现在“4.0”可用。我更改为“4.0”,认为这可以让我访问更新的 API。

I then tried to add the Tomcat 9 server. During the process, at "Add and Remove" it asks me which projects I want to add to be configured for the server. I selected my web project, but Eclipse said: "Tomcat version 9.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5, 6, 7, and 8 Web modules".

然后我尝试添加 Tomcat 9 服务器。在此过程中,在“添加和删除”中,它会询问我要为服务器配置哪些项目。我选择了我的 web 项目,但是 Eclipse 说:“Tomcat 9.0 版仅支持 J2EE 1.2、1.3、1.4 和 Java EE 5、6、7 和 8 Web 模块”。

Now as far as I know that's exactly what I'm using. But the only thing I had changed was the Dynamic Web Module. So I went back to my project configuration and tried to change "Dynamic Web Module" back to "3.1". Eclipse tells me:

现在据我所知,这正是我正在使用的。但我唯一改变的是动态 Web 模块。所以我回到我的项目配置并尝试将“动态 Web 模块”更改回“3.1”。Eclipse 告诉我:

Cannot change version of project facet Dynamic Web Module to 3.1.

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

Um… so I'll just remove it. I unchecked the box next to "Dynamic Web Module", and Eclipse tells me:

嗯……所以我就把它删除了。我取消选中“动态 Web 模块”旁边的框,Eclipse 告诉我:

Dynamic Web Module 4.0 cannot be uninstalled.

无法卸载 Dynamic Web Module 4.0。

Well that's a fine kettle of fish. I can't deploy my project to Tomcat, apparently because of the Dynamic Web Module. I can't change the Dynamic Web Module back to what it was. What do I do? Where does the problem lie?

嗯,这是一个很好的鱼锅。我无法将我的项目部署到 Tomcat,显然是因为动态 Web 模块。我无法将动态 Web 模块改回原来的状态。我该怎么办?问题出在哪里?

I opened Eclipse Bug 530844to see if I can get some reasons for this behavior.

我打开了Eclipse Bug 530844以查看是否可以找到导致此行为的一些原因。

采纳答案by skomisa

I reproduced the problem in the same environment as yours. When I tried to regress from 4.0 back to 3.1 I got the following error:

我在与您相同的环境中重现了该问题。当我尝试从 4.0 回归到 3.1 时,出现以下错误:

CannotDowngradeTo31

不能降级到 31

This blog provided the solution(which is a bit of a hack but it works):

这个博客提供了解决方案(这有点像黑客,但它有效):

  • Edit the file org.eclipse.wst.common.project.facet.core.xmlin the project's .settingsdirectory.
  • For the line containing facet="jst.web" version="4.0", change the version to 3.1.
  • 编辑项目的.settings目录中的文件org.eclipse.wst.common.project.facet.core.xml
  • 对于包含facet="jst.web" version="4.0" 的行,将版本更改为3.1

Also see this SO question: Dynamic Web Module 3.0 -- 3.1

另请参阅此 SO 问题:Dynamic Web Module 3.0 -- 3.1



A couple of related issues:

几个相关的问题:

  • It looks like something else may not be quite right with your setup to be getting that error "Tomcat version 9.0 only supports J2EE 1.2, 1.3, 1.4, and Java EE 5, 6, 7, and 8 Web modules". Is your project configured to use Servlet 4.0? For my Maven project I had to add this dependency to the POMfor Servlet 4.

  • Even after changing the Dynamic Web Module version to 3.1 my web app continued using version 4.0, so I'm not sure what that facet achieves.

  • 看起来您的设置可能不太正确,会出现“Tomcat 9.0 版仅支持 J2EE 1.2、1.3、1.4 和 Java EE 5、6、7 和 8 Web 模块”的错误。您的项目是否配置为使用 Servlet 4.0?对于我的 Maven 项目,我必须将此依赖项添加到Servlet 4的 POM中。

  • 即使将动态 Web 模块版本更改为 3.1,我的 Web 应用程序仍继续使用版本 4.0,因此我不确定该方面实现了什么。

回答by Benfarhat

My solution is a response to this message:

我的解决方案是对这条消息的回应:

Dynamic Web Module 4.0 cannot be uninstalled.

1 - So; if you can't uninstall Dynamic Web Module (i repeat: "Uninstall" not "change its version"), You can first edit in your project directory the file: .settings/org.eclipse.wst.common.project.facet.core.xmland manually uninstall it by removing this line:

1 - 所以; 如果您无法卸载动态 Web 模块(我再说一遍:“卸载”而不是“更改其版本”),您可以先在项目目录中编辑文件: .settings/org.eclipse.wst.common.project.facet.core.xml并通过删除以下行手动卸载它:

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

2 - After this, if you want to use dynamic web module 4.0, be sure that you use at least in your facets java 1.8 inside the same file .settings/org.eclipse.wst.common.project.facet.core.xml

2 - 在此之后,如果您想使用动态 Web 模块 4.0,请确保至少在您的 facets 中使用同一文件中的 java 1.8 .settings/org.eclipse.wst.common.project.facet.core.xml

<installed facet="java" version="1.8"/>

Or you can also change it in your "project Facets configuration" panel

或者您也可以在“项目方面配置”面板中更改它

3 - If the problem persist, take a look at your pom files and verify didn't force java version to 1.7, you should have these properties

3 - 如果问题仍然存在,请查看您的 pom 文件并确认没有将 java 版本强制为 1.7,您应该具有这些属性

    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>

Remember to update your project if you change your pom file: Maven > Update Projects

如果您更改 pom 文件,请记住更新您的项目:Maven > Update Projects

4 - Finally, if you still can't use Dynamic Web Module 4.0, juste choose between deleting your WEB-INF\web.xmlfile which can have a configuration for another dynamic web version like this:

4 - 最后,如果您仍然无法使用 Dynamic Web Module 4.0,请选择删除您的WEB-INF\web.xml文件,该文件可以为另一个动态 Web 版本进行配置,如下所示:

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

Otherwise you can manually change the supported version:

否则,您可以手动更改支持的版本:

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

return to the Project Facets configuration panel, a try once again to choose Dynamic Web Module 4.0, it should work

返回 Project Facets 配置面板,再次尝试选择 Dynamic Web Module 4.0,它应该可以工作

Hope this help.

希望这有帮助。

回答by Manuel Sopena Ballesteros

For me, this issue went away after removing the dependency below from my pom file.

对我来说,从我的 pom 文件中删除下面的依赖项后,这个问题就消失了。

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

hope that helps

希望有帮助