动态Web模块3.0 - 3.1

时间:2013-10-29 14:31:50

标签: eclipse spring maven spring-mvc

我有一个基于代码的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

此外,我无法删除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

后来我发现我可以通过将相应的插件插入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>

9 个答案:

答案 0 :(得分:70)

我在日食中遇到过类似的麻烦,唯一可以解决这个问题的方法是

  • 删除网络模块
  • 应用
  • 更改模块版本
  • 添加模块
  • 配置(对话框底部的其他配置可用链接)
  • 应用

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

编辑

如果没有别的帮助,这是第二种方式

  • 退出eclipse,转到文件系统中的项目,然后转到.settings文件夹。
  • 打开org.eclipse.wst.common.project.facet.core.xml制作备份,然后删除网络模块条目。
  • 您也可以在那里修改网络模块版本,但同样不能保证。

答案 1 :(得分:61)

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

  • http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd

请注意,3.0和3.1是不同的:在3.1中没有提及Sun,所以只需将3_0.xsd更改为3_1.xsd即可。

这应该是这样的:

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

另外,请确保您具有pom.xml中的最新版本。也就是说,

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.6</version>
    <configuration>
        ...
    </configuration>
</plugin>

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

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

答案 2 :(得分:9)

我遇到了同样的问题并通过编辑org.eclipse.wst.common.project.facet.core.xml解决了这个问题。

在此文件中,我可以更改以下行

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

回到

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

这似乎解决了我的问题。

答案 3 :(得分:3)

我在Win7上运行,Tomcat7在Eclipse Mars上设置了maven-pom,启用了maven项目。 在NOT运行的服务器上,我只需在此屏幕上从3.1更改为3.0: enter image description here

对我而言,禁用动态Web模块非常重要!然后更改版本,然后再次启用动态Web模块。

答案 4 :(得分:2)

打开Eclipse项目属性,在Project Facets中取消选择&#34; Dynamic Web Module&#34;,...单击OK Maven - &gt;更新项目

答案 5 :(得分:1)

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

如果您应用更改,这就是您将面临空指针异常的原因。

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

答案 6 :(得分:0)

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

答案 7 :(得分:0)

1)转到您的项目并找到“.settings”目录this one
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>

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

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>  

答案 8 :(得分:0)

  1. 转到工作区位置
  2. 选择您的项目文件夹
  3. 。设置文件夹
  4. 编辑“ org.eclipse.wst.common.project.facet.core”
  5. 更改已安装的facet =“ jst.web”版本=“ 3.0”