在Eclipse Maven项目中更改动态Web模块版本 [英] Changing Dynamic Web Module version in Eclipse Maven Project

查看:119
本文介绍了在Eclipse Maven项目中更改动态Web模块版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置Dynamic Web Module 3.0以支持Java 6开发。每当我执行 Maven>更新项目时,我的eclipse问题选项卡中出现此错误。

I'm trying to set up Dynamic Web Module 3.0 in order to support Java 6 development. I'm getting this error in my Problems tab of eclipse whenever I do Maven > Update Project.

动态Web模块3.1需要Java 1.7或更高版本。

出现好像什么都没发生错了,但我必须遗漏一些东西,因为我一直收到这个错误。

It appears as though nothing is going wrong, but I must be missing something because I consistently receive this error.

以下是我的.settings / org.eclipse.wst.common.project.facet的内容.core.xml

Below is the contents of my .settings/org.eclipse.wst.common.project.facet.core.xml

<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
  <fixed facet="jst.java"/>
  <fixed facet="jst.web"/>
  <installed facet="jst.java" version="1.6"/>
  <installed facet="jst.web" version="3.0"/>
</faceted-project>

在eclipse中,我的Java编译器正确设置为1.6。在Project Facets选项卡中,Dynamic Web Module被正确指定为版本3.0,而Java在Project Facets下也显示为1.6。

In eclipse, my Java Compiler is set to 1.6 properly. In the Project Facets tab, Dynamic Web Module is specified as version 3.0 correctly, and Java also appears as 1.6 under Project Facets.

在我的pom.xml文件中,我有还相应地设置了Java版本:

In my pom.xml file, I have also set the Java version accordingly:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
</plugin>

作为旁注,我还要提一下,我正在做一个带有<的纯Java构建code> WebApplicationInitializer 并且没有web.xml文件。

As a side note, I should also mention that I am doing a pure-Java build with a WebApplicationInitializer and have no web.xml file.

我非常感谢任何帮助,因为我试图压制这个看似无关的错误消息。

Any help is greatly appreciated as I attempt to squash this seemingly irrelevant error message.

编辑:添加了pom.xml内容

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>net.XXXXX</groupId>
    <artifactId>XXXXX</artifactId>
    <version>1.0-SNAPSHOT</version>

    <name>XXXXX</name>
    <packaging>war</packaging>
    <url>http://maven.apache.org</url>

    <build>
        <finalName>XXXXX</finalName>

        <plugins>

            <!-- Source level should be 1.6 (not Maven default) for Java EE 6 projects -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>

            <!-- When using xml-less approach, need to disable Maven's warning about 
                missing web.xml -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>

        </plugins>
    </build>
    <dependencies>

        <!-- JUnit testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

        <!-- Spring Core -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <!-- Spring MVC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <!-- Spring Context without commons-logging -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.0.2.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Spring Security core -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- Spring Security config -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- Spring Security web -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>3.2.1.RELEASE</version>
        </dependency>

        <!-- jcl-over-slf4j -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>jcl-over-slf4j</artifactId>
            <version>1.7.6</version>
        </dependency>

        <!-- slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.7.6</version>
        </dependency>

        <!-- slf4j-log4j12 -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.6</version>
        </dependency>

        <!-- log4j -->
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- Need servlet API for compiling the classes. Not needed in runtime -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Required for xml-less configuration of Spring via @Configuration annotations -->
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib-nodep</artifactId>
            <version>3.1</version>
        </dependency>

        <!-- Required for getting Spring working with Hibernate -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.0.2.RELEASE</version>
        </dependency>

        <!-- Hibernate -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.4.Final</version>
        </dependency>

        <!-- For using JPA instead of "pure Hibernate" -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.4.Final</version>
        </dependency>

        <!-- DB connection pooling for production applications -->
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>20030825.184428</version>
        </dependency>

        <!-- Concrete JDBC driver for MySQL DB -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.29</version>
        </dependency>

        <!-- Add Taglib support -->
        <dependency>
            <groupId>jstl</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>

    </dependencies>

</project>


推荐答案

在我们的项目中,我们添加更改 web.xml 根元素的声明,更改自:

In an our project, we add to change the web.xml root element's declaration, changing from:

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

to:

<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_2_5.xsd"
         version="2.5" >

可能Eclipse期望它满足不同的Servlet版本规范。在我们的例子中,我们既没有编译也没有运行时问题。

Probably Eclipse were expecting it as satisfying a different Servlet version spec. In our case too, we had neither compile nor runtime problems.

编辑:在您的情况下,您没有使用web.xml文件,有以下pom的依赖,这可能会混淆Eclipse的maven插件:

In your case, where you were not using a web.xml file, there was the following pom's dependency which probably was confusing Eclipse's maven plugin:

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

将其更改为3.0.1。 (事实证明, WebApplicationInitializer 需要 Servlet 3.0+环境而不是3.1 +)

Change it to "3.0.1". (It turns out that WebApplicationInitializer requires "Servlet 3.0+ environments" and not 3.1+)

这篇关于在Eclipse Maven项目中更改动态Web模块版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆