spring 动态网页模块 3.0 -- 3.1

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

Dynamic Web Module 3.0 -- 3.1

eclipsespringmavenspring-mvc

提问by du-it

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

我有一个基于代码的 mavenized 配置 Spring 3.2.4 Web 应用程序。当我首先使用 Maven/pom.xml 构建应用程序时,我收到一个错误,指出缺少 web.xml。首先我尝试创建一个空的 web.xml。这是项目方面发生变化的时刻(我不知道为什么)。它从动态 Web 模块 3.0 切换到 3.1,这是不可逆转的。如何再次将其更改为 Dynamic Web Modules 3.0 ???

enter image description here

在此处输入图片说明

Additionally I can't remove the JAX-RS. Trying this it results in:

此外,我无法删除 JAX-RS。尝试这样做会导致:

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:

后来我发现我可以通过将相应的插件插入到 pom.xml 中来避免 Maven 编译错误:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>
        <failOnMissingWebXml>false</failOnMissingWebXml>
    </configuration>
</plugin>

回答by dimoniy

I had similar troubles in eclipse and the only way to fix it for me was to

我在 eclipse 中遇到了类似的问题,为我解决它的唯一方法是

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

只需确保在应用之前配置 web 模块,因为默认情况下它会在 /WebContent/ 中查找您的 web 文件,这不是 Maven 项目结构应该是什么。

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.
  • 退出 eclipse,转到文件系统中的项目,然后转到 .settings 文件夹。
  • 打开org.eclipse.wst.common.project.facet.core.xml进行备份,然后删除 Web 模块条目。
  • 您也可以在那里修改 Web 模块版本,但同样不能保证。

回答by Alexey Grigorev

If you want to use version 3.1 you need to use the following schema:

如果要使用 3.1 版,则需要使用以下架构:

  • http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd
  • 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.xsdto 3_1.xsdwon't work.

请注意,3.0 和 3.1 是不同的:在 3.1 中没有提到 Sun,所以简单地更改3_0.xsd3_1.xsd将不起作用。

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,

另外,请确保您依赖于pom.xml. 那是,

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

最后,您应该使用 Java 7 或 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>

回答by Nlp Trinh

I had the same problem and fixed this by editing org.eclipse.wst.common.project.facet.core.xml.

我遇到了同样的问题,并通过编辑 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.

这似乎解决了我的问题。

回答by Dirk Schumacher

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

我在 Win7、Tomcat7 上运行,在 Eclipse Mars 上设置了 maven-pom,并启用了 maven 项目。在未运行的服务器上,我只需在此屏幕上从 3.1 更改为 3.0: 在此处输入图片说明

For me it was important to have Dynamic Web Module disabled! Then change the version and then enable Dynamic Web Module again.

对我来说,禁用动态 Web 模块很重要!然后更改版本,然后再次启用动态 Web 模块。

回答by CamelTM

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

打开 Eclipse 项目属性,在 Project Facets 中取消选择“Dynamic Web Module”,...单击 OK Maven -> Update project

回答by Donatello Boccaforno

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.

在特定情况下,问题是由于为动态 webapp 发布的 maven-archetype-webapp,面向 ver.2.5(请参阅生成的 web.xml 和相关的 xsd)并且它与 eclipse 相关。当您尝试将项目方面更改为动态 webapp > 2.5 时,src 文件夹结构将在语法上发生变化(2.5 与 3.1 不同),但不会发生财务变化。

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.

要解决它,您必须从项目构面配置中设置默认配置。应用更改,然后进入 Java 构建路径,您必须删除 /src 文件夹并至少创建 /src/main/java 文件夹(还需要 /src/main/resources 和 /src/test/java兼容)重新更改为您想要的所需配置(3.0、3.1),然后应用。

回答by Long Tran

1) Go to your project and find ".settings" directory this one
2) Open file xml named:
org.eclipse.wst.common.project.facet.core.xml
3)

1)转到您的项目并找到“.settings”目录这一个
2)打开文件xml命名为:
org.eclipse.wst.common.project.facet.core.xml
3)

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

将 jst.web 版本更改为 3.0,将 java 版本更改为 1.7 或 1.8(基于您当前使用的 jdk 版本)

4) Change your web.xmlfile under WEB-INFdirectory , please refer to this article:
https://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/
5) Go to pom.xmlfile and paste these lines:

4)更改web.xml目录下的WEB-INF文件,请参考这篇文章:
https: //www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/
5)转到pom.xml文件并粘贴这些行:

<build>
    <finalName>YOUR_PROJECT_NAME</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.3</version>
            <configuration>
                <source>1.8</source> THIS IS YOUR USING JDK's VERSION
                <target>1.8</target> SAME AS ABOVE
            </configuration>
        </plugin>
    </plugins>
</build>  

回答by Prakash BM

  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"
  1. 转到工作区位置
  2. 选择您的项目文件夹
  3. .setting文件夹
  4. 编辑“org.eclipse.wst.common.project.facet.core”
  5. 更改已安装的 facet="jst.web" version="3.0"

回答by Afshin Ghazi

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.

我打开了项目 org.eclipse.wst.common.project.facet.core.xml 并首先更改然后删除了带有 web 模块标记的行。每次都清理项目并在 Tomcat 上启动,但它仍然没有运行。返回线路(原样)并清理项目。在 Eclipse 中打开 Tomcat 设置并手动添加项目到 Tomcat 启动(右键单击 + 添加和删除)。单击项目并选择在服务器上运行....一切都很好。