在我的maven项目中,我有这个有效的POM:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>spring</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>example</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.0.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.4.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.2.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.2.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.0.Final</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>4.0.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.0.3.RELEASE</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>C:\Users\Kleber\Downloads\Projetos\example\src\main\java</sourceDirectory>
<scriptSourceDirectory>C:\Users\Kleber\Downloads\Projetos\example\src\main\scripts</scriptSourceDirectory>
<testSourceDirectory>C:\Users\Kleber\Downloads\Projetos\example\src\test\java</testSourceDirectory>
<outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\classes</outputDirectory>
<testOutputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\test-classes</testOutputDirectory>
<resources>
<resource>
<directory>C:\Users\Kleber\Downloads\Projetos\example\src\main\resources</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>C:\Users\Kleber\Downloads\Projetos\example\src\test\resources</directory>
</testResource>
</testResources>
<directory>C:\Users\Kleber\Downloads\Projetos\example\target</directory>
<finalName>example-0.0.1-SNAPSHOT</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.3</version>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-5</version>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<artifactId>maven-release-plugin</artifactId>
<version>2.0</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>TomcatServer</server>
<path>/webappExample</path>
<username>user001</username>
<password>123</password>
</configuration>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<id>default-clean</id>
<phase>clean</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<id>default-install</id>
<phase>install</phase>
<goals>
<goal>install</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>default-resources</id>
<phase>process-resources</phase>
<goals>
<goal>resources</goal>
</goals>
</execution>
<execution>
<id>default-testResources</id>
<phase>process-test-resources</phase>
<goals>
<goal>testResources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>default-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<executions>
<execution>
<id>default-testCompile</id>
<phase>test-compile</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
<execution>
<id>default-compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<executions>
<execution>
<id>default-war</id>
<phase>package</phase>
<goals>
<goal>war</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>default-deploy</id>
<phase>deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.0</version>
<executions>
<execution>
<id>default-site</id>
<phase>site</phase>
<goals>
<goal>site</goal>
</goals>
<configuration>
<outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
<execution>
<id>default-deploy</id>
<phase>site-deploy</phase>
<goals>
<goal>deploy</goal>
</goals>
<configuration>
<outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
<reportPlugins>
<reportPlugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
</reportPlugin>
</reportPlugins>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<outputDirectory>C:\Users\Kleber\Downloads\Projetos\example\target\site</outputDirectory>
</reporting>
</project>
此时,在Eclipse IDE的Markers选项卡中,出现了此错误:
Description Resource Path Location Type
Dynamic Web Module 3.0 requires Java 1.6 or newer. example line 1 Maven Java EE Configuration Problem
One or more constraints have not been satisfied. example line 1 Maven Java EE Configuration Problem
我尝试在我的项目的构建路径中修复此配置(在属性/ Java构建路径中),但是当我运行Maven&gt;更新项目,此选项的值返回到上一个。
我应该在哪里更改此选项以修复此错误?
答案 0 :(得分:43)
Build Path
并将Java Library版本更改为1.7
1.7
Dynamic Web Module
,然后点击应用(如果有,请取消选中JavaServer Faces
)Java
构面版本更改为1.7
,然后点击应用 Dyanmic Web Module v3.0
,申请。 Eclipse的facet配置有问题。确保在检查和取消检查方面之间保持Apply
。
链接:
答案 1 :(得分:28)
GGrec的解决方案对我不起作用。我设法通过添加到pom.xml来修复此问题:
<build>
<finalName>finalName</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source> <!-- yours Java version -->
<target>1.8</target> <!-- yours Java version -->
</configuration>
</plugin>
</plugins>
</build>
更新: 另外我发现每次在这个pom.xml上运行mvn install命令时它都会覆盖以前的配置。正确的解决方案是从pom.xml中删除此版本并在eclipse选项中进行设置,或者只使用pom.xml中的配置。
答案 2 :(得分:7)
执行上述故障排除步骤后。更新您的maven项目。
右键点击您的项目 - &gt;行家 - &GT;更新项目
或者只是Alt + f5。
希望这可能有助于某人。
答案 3 :(得分:3)
另外,作为Kefas,我将java版本指定为1.7并且它可以工作!
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
答案 4 :(得分:2)
以上建议对我有帮助! 右键单击项目 - &gt;属性 - &gt; Project Facets,然后将Java facets版本更改为1.7。
如果它不起作用,请将以下代码添加到pom.xml:
<build>
<finalName>finalName</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source> <!-- yours Java version -->
<target>1.7</target> <!-- yours Java version -->
</configuration>
</plugin>
</plugins>
</build>
保存pom.xml。
然后,右键单击项目 - &gt; Maven - &gt;更新项目。
答案 5 :(得分:1)
这可能听起来很傻,但我刚做了Project-&gt; Clean,然后是Maven-&gt; Update。
解决了这个问题。
答案 6 :(得分:0)
我正在使用java 1.8。修复了以下操作。
从pom中删除:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
它会抱怨pom不是最新的。 使用快速修复来更新然后你会得到一大堆错误。
重新加入pom:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
更新了maven并清除了所有错误。
答案 7 :(得分:0)
这对我有用:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<warName>mfp</warName>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</pluginManagement>
<finalName>myprojectname</finalName>
</build>
答案 8 :(得分:0)
将版本更改为3.1,将标记更改为1.7
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
答案 9 :(得分:0)
我必须将“窗口”->“首选项”->“ Maven”->“用户设置”中的Maven设置重置为“ C:\ Development \ apache-maven-3.5.3 \ conf \ settings.xml”。
答案 10 :(得分:0)
正确的答案是:-一件简单的事情 大多数情况下,您无法将动态Web模块版本更改为3.0 ..它必须默认设置为2.3或2.4或其他。它不会起作用 右键单击项目->首选项->项目构面->取消选中动态Web模块,然后将版本更改为3.0,然后进行检查。而且我认为您必须为此更改最新版本(即1.7或更高版本)。之后,点击“应用并关闭”按钮。
然后更新maven项目。.右键单击项目,选择maven->更新项目。 仍然会为我们80%的人继续造成错误。
真正的解决方案在这里 1>转到您的工作空间文件夹 2>然后转到您的项目文件夹 3>检查.settings文件(有时它可能被隐藏然后取消隐藏..(机会很少) 4>进入该.settings文件,然后检查org.eclipse.wst.common.project.facet.core.xml文件,并使用notepad ++或类似的东西进行编辑。在此处输入代码 5>这是其中的代码
<?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.4"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
像这样将jst.web版本更改为3.0
<?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="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
然后最后更新Maven ..然后重新启动Eclipse或另一个IDE
答案 11 :(得分:0)
我在pom.xml中添加了以下代码行,并且可以正常工作。
<properties>
<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>