我正在尝试设置Dynamic Web Module 3.0以支持Java 6开发。我每次Maven > Update Project
时都会在我的“问题”选项卡中收到此错误。
Dynamic Web Module 3.1 requires Java 1.7 or newer.
它似乎好像什么都没有出错,但我必须遗漏一些东西,因为我一直都会收到这个错误。
以下是我的.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。
在我的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>
作为旁注,我还应该提到我正在使用WebApplicationInitializer
进行纯Java构建,并且没有web.xml文件。
我非常感谢任何帮助,因为我试图压制这个看似无关紧要的错误消息。
编辑:添加了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>
答案 0 :(得分:18)
在我们的项目中,我们添加更改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">
到:
<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版本规范。在我们的例子中,我们既没有编译也没有运行时问题。
编辑:在您没有使用web.xml文件的情况下,存在以下pom的依赖关系,这可能会让Eclipse的maven插件感到困惑:< / p>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
将其更改为&#34; 3.0.1&#34;。 (事实证明WebApplicationInitializer需要&#34; Servlet 3.0+环境&#34;而不是3.1 +)
答案 1 :(得分:12)
您可以将其添加到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>
适用于Spring STS 3.6.3:)
编辑:
来源:http://crunchify.com/how-to-solve-dynamic-web-module-3-1-requires-java-1-7-or-newer-in-eclipse/
答案 2 :(得分:0)
尝试将JRE / JDK版本更改为1.7。 Web项目模块不支持1.6。