Java 无法将项目方面动态 Web 模块的版本更改为 3.0?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18122336/
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
Cannot change version of project facet Dynamic Web Module to 3.0?
提问by EdgarZeng
I am using maven to create a dynamic webapp in Eclipse. I added some folders like src/test/java
and src/test/resources
. Also I changed the library in Java Build Path to obtain the JavaSE-1.7. It's all OK up to here.
我正在使用 maven 在 Eclipse 中创建一个动态 webapp。我添加了一些文件夹,如src/test/java
和src/test/resources
。我还更改了 Java Build Path 中的库以获得 JavaSE-1.7。到这里一切正常。
When I tried to change the Projects Facet Dynamic Web Module something went wrong. I had change the Java to 1.7 in the same place. And it still told me, cannot change version of project facet Dynamic Web Module to 3.0.
当我尝试更改 Projects Facet 动态 Web 模块时,出现了问题。我在同一个地方将 Java 更改为 1.7。它仍然告诉我,不能将项目方面动态 Web 模块的版本更改为 3.0。
I have changed everything that would effect the changing I think.
我已经改变了所有会影响我认为的改变的东西。
采纳答案by Sydney
I updated my web.xml
我更新了我的 web.xml
<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 enkor
Another way is to edit the project facet configuration file itself: org.eclipse.wst.common.project.facet.core.xml
另一种方法是编辑项目构面配置文件本身: org.eclipse.wst.common.project.facet.core.xml
Change the dynamic web module version in this line to 3.0 - <installed facet="jst.web" version="2.5"/>
将此行中的动态 web 模块版本更改为 3.0 - <installed facet="jst.web" version="2.5"/>
And then:
进而:
- Right-click on the project (in the Project Explorerpanel).
- Select Maven ? Update Project(or press Alt+F5)
- 右键单击项目(在Project Explorer面板中)。
- 选择Maven ?更新项目(或按Alt+F5)
You'll find this file in the .settings
directory within the Eclipse project.
您将.settings
在 Eclipse 项目的目录中找到该文件。
回答by keiki
In my case the web.xml was referenced by a dtd. After I changed this to xsd reference like the one posted by Sydney it worked.
在我的情况下,web.xml 被 dtd 引用。在我将其更改为 xsd 参考后,就像悉尼发布的那样,它起作用了。
回答by Adrian Ber
I had the same issue and I even tried to remove the project and add it again. What did the trick was to remove the .settings
directory.
我遇到了同样的问题,我什至尝试删除该项目并重新添加。诀窍是删除.settings
目录。
回答by GAURAV KUMAR GUPTA
you please open the Navigator view and following step
请打开导航器视图并执行以下步骤
- (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.
- Change the dynamic web module version in this line to 2.5 -
- Change the Java version in this line to 1.5 or higher - .
- (Window > Show View > Other > General)发现你的项目下有一个.settings文件夹,展开它然后打开文件“org.eclipse.wst.common.project.facet.core.xml”,使下面的更改并保存文件。
- 将此行中的动态 Web 模块版本更改为 2.5 -
- 将此行中的 Java 版本更改为 1.5 或更高版本 - 。
回答by pagurix
I think I had the same problem as you. My web.xml had version 2.5 while the project had the (right-click on Project-> Properties-> Project Facets->) Dynamic Web Module 2.3.
我想我和你有同样的问题。我的 web.xml 有 2.5 版,而项目有(右键单击 Project-> Properties-> Project Facets->)Dynamic Web Module 2.3。
Although I tried to change the version from 2.3 to 2.5 ECLIPSE did not permit it. Solution: I removed the check mark under the heading Dynamic Web Module, I saved and I had Update Project. Automatically re-awakening is entering the box with the correct version. I use Eclipse Kepler.
尽管我尝试将版本从 2.3 更改为 2.5,但 ECLIPSE 不允许。解决方案:我删除了标题动态 Web 模块下的复选标记,我保存并更新了项目。自动重新唤醒是输入正确版本的框。我使用 Eclipse 开普勒。
p.s.: look at the comments of Jonathanjust below, very useful.
回答by Ryan J. McDonough
The web.xml trick works because you're now explicitly telling WTP that you are using that specific servlet version, regardless of what the container supports.
web.xml 技巧有效,因为您现在明确告诉 WTP 您正在使用该特定 servlet 版本,而不管容器支持什么。
In my case, I am using the annotation config within a Maven project and I do not have a web.xml file. It turns out that in the absence of a web.xml, WTP looks at your Maven dependencies to determine what Servlet version to use. In my case, I had defined the following:
就我而言,我在 Maven 项目中使用注释配置,但我没有 web.xml 文件。事实证明,在没有 web.xml 的情况下,WTP 会查看您的 Maven 依赖项以确定要使用的 Servlet 版本。就我而言,我定义了以下内容:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
Changing it to 6.0 fixed the problem and it's now using Servlet 3.0 instead of 3.1, which is the default for JavaEE 7. Since I had to go from Tomcat 8 to Tomcat 7, Tomcat 7 only supports the JavaEE 6 Web profile. Now things work wonderfully.
将其更改为 6.0 解决了问题,它现在使用 Servlet 3.0 而不是 3.1,这是 JavaEE 7 的默认值。由于我必须从 Tomcat 8 转到 Tomcat 7,因此 Tomcat 7 仅支持 JavaEE 6 Web 配置文件。现在一切都很好。
回答by Siddaram
Open web.xml from project structure http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> Servlet 3.0 Web Application
从项目结构 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0"> Servlet 3.0 Web Application 打开 web.xml
and update web.xml file for example change version = "2.5"
并更新 web.xml 文件,例如更改 version = "2.5"
Also change the org.eclipse.wst.common.project.facet.core.xml file from your project .settings file Follow the steps 1. Window > Show View > Other > General > Navigator
还要从您的项目 .settings 文件中更改 org.eclipse.wst.common.project.facet.core.xml 文件按照步骤 1. Window > Show View > Other > General > Navigator
There is a .settings folder under your project directory
Change the dynamic web module version in this line to 2.5 4.Change the Java version in this line to 1.5 or higher
您的项目目录下有一个 .settings 文件夹
把这行动态web模块版本改成2.5 4.把这行Java版本改成1.5或更高
Now refresh your project and get set to run on your server.
现在刷新您的项目并设置为在您的服务器上运行。
Do follow the blog for the solution http://scrapillars.blogspot.in/2014/02/how-to-change-project-facet-in-eclipse.html
请关注解决方案的博客 http://scrapillars.blogspot.in/2014/02/how-to-change-project-facet-in-eclipse.html
The solution is produced with image illustrations
解决方案是用图像插图制作的
回答by kashili kashili
Doing maven update or reimporting the project did not help. @Sydney's answer is right; in addition I have to recreate the project in different workspace as said in JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer
执行 Maven 更新或重新导入项目没有帮助。@Sydney 的回答是对的;此外,我必须在不同的工作区中重新创建项目,如JavaServer Faces 2.2 中所述,需要动态 Web 模块 2.5 或更高版本
回答by Pintér Tamás
Delete
删除
.settings
.classpatch
.projejct
target
and import again the maven project.
并再次导入maven项目。