Java 在 Eclipse Maven 项目中更改动态 Web 模块版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22405212/
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
Changing Dynamic Web Module version in Eclipse Maven Project
提问by Geoffrey Tucker
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
.
我正在尝试设置 Dynamic Web Module 3.0 以支持 Java 6 开发。每当我这样做时,我都会在 Eclipse 的问题选项卡中收到此错误Maven > Update Project
。
Dynamic Web Module 3.1 requires Java 1.7 or newer.
Dynamic Web Module 3.1 requires Java 1.7 or newer.
It appearsas though nothing is going wrong, but I must be missing something because I consistently receive this error.
这看起来好像没有什么会错,但我一定是失去了一些东西,因为我一直收到此错误。
Below is the contents of my .settings/org.eclipse.wst.common.project.facet.core.xml
下面是我的 .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>
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.
在 Eclipse 中,我的 Java 编译器正确设置为 1.6。在 Project Facets 选项卡中,Dynamic Web Module 被正确指定为 3.0 版,Java 在 Project Facets 下也显示为 1.6。
In my pom.xml file, I have also set the Java version accordingly:
在我的 pom.xml 文件中,我还相应地设置了 Java 版本:
<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>
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.
作为旁注,我还应该提到我正在使用 a 进行纯 Java 构建WebApplicationInitializer
并且没有 web.xml 文件。
Any help is greatly appreciated as I attempt to squash this seemingly irrelevant error message.
当我试图消除这个看似无关的错误消息时,非常感谢任何帮助。
EDIT: added pom.xml contents
编辑:添加 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>
采纳答案by robermann
In an our project, we add to change the web.xml
root element's declaration, changing from:
在我们的项目中,我们添加更改web.xml
根元素的声明,更改为:
<!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" >
Probably Eclipse were expecting it as satisfying a different Servlet version spec. In our case too, we had neither compile nor runtime problems.
可能 Eclipse 期望它满足不同的 Servlet 版本规范。在我们的例子中,我们也没有编译和运行时问题。
EDIT: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:
编辑:在您的情况下,您没有使用 web.xml 文件,以下 pom 的依赖项可能会混淆 Eclipse 的 maven 插件:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Change it to "3.0.1". (It turns out that WebApplicationInitializerrequires "Servlet 3.0+ environments" and not 3.1+)
将其更改为“3.0.1”。(事实证明,WebApplicationInitializer需要“ Servlet 3.0+ 环境”而不是 3.1+)
回答by Akshay
Try changing your JRE/JDK version to 1.7. The web project module doesn't support 1.6.
尝试将您的 JRE/JDK 版本更改为 1.7。Web 项目模块不支持 1.6。
回答by Enrique San Martín
you can add this to the pom.xml:
您可以将其添加到 pom.xml 中:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
Works in Spring STS 3.6.3 :)
适用于 Spring STS 3.6.3 :)
edit:
编辑:
source: http://crunchify.com/how-to-solve-dynamic-web-module-3-1-requires-java-1-7-or-newer-in-eclipse/
来源:http: //crunchify.com/how-to-solve-dynamic-web-module-3-1-requires-java-1-7-or-newer-in-eclipse/