Maven Java EE 配置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23183931/
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
Maven Java EE Configuration
提问by Kleber Mota
In my maven project, I have this Effective POM:
在我的 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>
In this moment, in the Markers tab on my Eclipse IDE, this error is being presented:
此时,在我的 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
I try fix this configuration in the Build path from my project (In Properties/Java Build Path), but when I run Maven > Update Project, the value for this option returned to the previous one.
我尝试在我的项目的构建路径中修复此配置(在属性/Java 构建路径中),但是当我运行 Maven > 更新项目时,此选项的值返回到前一个。
Where I should change this option to fix this error?
我应该在哪里更改此选项以修复此错误?
采纳答案by GGrec
- Go to project
Build Path
and change the Java Library version to1.7
- Go to Eclipse Preferences -> Java -> Compiler -> Change compliance level to
1.7
- Right click on project -> Properties -> Project Facets
- Uncheck
Dynamic Web Module
and click Apply(also uncheckJavaServer Faces
if you had that) - Change the
Java
facet version to1.7
and click Apply - Add the
Dyanmic Web Module v3.0
, apply.
- 转到项目
Build Path
并将 Java 库版本更改为1.7
- 转到 Eclipse 首选项 -> Java -> 编译器 -> 将合规级别更改为
1.7
- 右键单击项目 -> 属性 -> 项目构面
- 取消选中
Dynamic Web Module
并单击应用(JavaServer Faces
如果您有,也取消选中) - 将
Java
构面版本更改为1.7
并单击应用 - 添加
Dyanmic Web Module v3.0
,应用。
Eclipse's facets configuration is buggy. Make sure you keep hitting Apply
between checking and unchecking of facets.
Eclipse 的 facets 配置有问题。确保Apply
在检查和取消检查方面之间保持一致。
Links:
链接:
回答by Kefas
GGrec's solution doesn't work for me. I manage to fixed this issue by adding to pom.xml this:
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>
UPDATE: In addition I figured out that everytime you run mvn install command on this pom.xml it overrides previous configuration. The right solution is either remove this version from pom.xml and set it up in eclipse options or just use configuration from pom.xml.
更新:此外,我发现每次在 pom.xml 上运行 mvn install 命令时,它都会覆盖以前的配置。正确的解决方案是从 pom.xml 中删除此版本并在 eclipse 选项中进行设置,或者仅使用 pom.xml 中的配置。
回答by Nordknight
Also as Kefas I am specify java version to 1.7 and it works!
同样作为 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>
回答by kwm
I am using java 1.8. Fixed doing the following.
我正在使用 Java 1.8。固定执行以下操作。
Remove from pom:
从 pom 中删除:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
It will complain that pom is not up to date. Used quick fix to update then you get a whole bunch of errors.
它会抱怨 pom 不是最新的。使用快速修复来更新然后你会得到一大堆错误。
RE-ADD to pom:
重新添加到 pom:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
Updated maven and all errors are cleared.
更新了 Maven 并清除了所有错误。
回答by Milos
This works for me:
这对我有用:
<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>
回答by Hem M
After following above troubleshooting steps. Update your maven project.
按照上述故障排除步骤后。更新您的 Maven 项目。
Right click on your project--> Maven--> Update Project
Or simply Alt+f5.
右键单击您的项目--> Maven--> 更新项目
或者干脆Alt+f5。
Hope this might help someone.
希望这可以帮助某人。
回答by Puneet
This might sound silly but I just did Project->Clean and then Maven->Update.
这听起来可能很傻,但我只是做了项目->清理然后Maven->更新。
Solved the problem.
解决了问题。
回答by Ethan
The above suggests is helpful for me! Right click on project -> Properties -> Project Facets, then change the Java facets version to 1.7.
以上建议对我有帮助!右键单击项目-> 属性-> Project Facets,然后将Java facets 版本更改为1.7。
If it doesn't work, add the following code to pom.xml:
如果不起作用,在 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>
Save pom.xml.
保存 pom.xml。
And then, right click on project-->Maven-->Update Project.
然后,右键单击项目--> Maven--> 更新项目。
回答by Yuri Ferreira
Changed version to 3.1 and the tags and to 1.7
将版本更改为 3.1 并将标签更改为 1.7
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
回答by handro1104
I had to reset maven settings in Window->Preferences->Maven-> User Settings to "C:\Development\apache-maven-3.5.3\conf\settings.xml".
我不得不将 Window->Preferences->Maven-> User Settings 中的 maven 设置重置为“C:\Development\apache-maven-3.5.3\conf\settings.xml”。