我已经构建了一个小应用程序。现在我想将我的依赖项从已下载的* .jar替换为Maven。
Maven显然试图用Java 5构建它。但它应该是Java 7。
如何告诉maven使用JDK 1.7?
$ mvn clean install
// ...
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/foo/bar.java:[17,37] diamond operator is not supported in -source 1.5
(use -source 7 or higher to enable diamond operator)
[INFO] 2 errors
[INFO] -----------------
// ...
这是我的pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo.bar</groupId>
<artifactId>bar</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.googlecode.htmlcompressor</groupId>
<artifactId>htmlcompressor</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>com.yahoo.platform.yui</groupId>
<artifactId>yuicompressor</artifactId>
<version>2.4.6</version>
</dependency>
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd-core</artifactId>
<version>3.6.6</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:1)
您需要将以下插件定义添加到project/build/plugins
<project ... >
...
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
...
</project>
这将告诉maven编译器插件使用Java 1.7进行编译。