2015-06-24 95 views
1

我已經構建了一個小應用程序。現在我想將我的依賴關係從下載的* .jar替換爲Maven。Maven試圖編譯爲1.5

的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> 

回答

1

你需要以下插件定義添加到您的pom.xml下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。