2011-12-14 55 views
2

可能重複:
Maven Install: 「Annotations are not supported in -source 1.3」我用maven測試運行我的項目,但它說我是用JDK 1.3

我使用Ubuntu 10.04和開放JDK-1.6.0。

這是我MVN -version輸出:

Apache Maven 2.2.1 (rdebian-1) 
Java version: 1.6.0_20 
Java home: /usr/lib/jvm/java-6-openjdk/jre 
Default locale: en_US, platform encoding: UTF-8 
OS name: "linux" version: "2.6.32-37-generic" arch: "i386" Family: "unix" 

但是當我運行mvn測試,存在一些誤區:

/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/DataTypeTest.java:[3,7] static import declarations are not supported in -source 1.3 
(use -source 5 or higher to enable static import declarations) 
import static org.junit.Assert.assertEquals; 

/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/DataTypeTest.java:[11,2] annotations are not supported in -source 1.3 
(use -source 5 or higher to enable annotations) 
@Test 

/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/ChannelBufferTest.java:[3,7] static import declarations are not supported in -source 1.3 
(use -source 5 or higher to enable static import declarations) 
import static org.junit.Assert.*; 

/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/ChannelBufferTest.java:[11,2] annotations are not supported in -source 1.3 
(use -source 5 or higher to enable annotations) 
@Test 

/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/PathTest.java:[3,7] static import declarations are not supported in -source 1.3 
(use -source 5 or higher to enable static import declarations) 
import static org.junit.Assert.*; 

/home/unionx/workspace/java/try-netty/src/test/java/net/bluedash/trynetty/PathTest.java:[11,2] annotations are not supported in -source 1.3 
(use -source 5 or higher to enable annotations) 
@Test 

我看來,MVN以爲我用Java 1.3的,也許它只是支持Java 1.5?

+0

發佈您的pom.xml – subodh 2011-12-14 05:58:23

回答

13

http://maven.apache.org/general.html#Compiling-J2SE-5

如何設置Maven的,因此會與我選擇的目標和源JVM編譯? 您必須在您的pom中配置源和目標參數。例如,要將源和目標JVM設置爲1.5,您應該在您的POM中:

... 
<build> 
... 
    <plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.3.2</version> 
     <configuration> 
     <source>1.5</source> 
     <target>1.5</target> 
     </configuration> 
    </plugin> 
    </plugins> 
... 
</build> 
... 
+0

我將此代碼段添加到我的pom.xml中,並且它工作正常。我想我應該檢查maven的文檔。謝謝。 – unionx 2011-12-14 06:17:40

1

檢查您的POM文件。你可能有一個編譯器插件的插件配置,告訴Maven使用Java 1.3。有關詳細信息,請參見this page

1

檢查您的POM文件並添加您的編譯器版本,如下所示。

<project> 
    [...] 
    <build> 
    [...] 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>2.3.2</version> 
     <configuration> 
      <verbose>true</verbose> 
      <fork>true</fork> 
      <executable><!-- path-to-javac --></executable> 
      <compilerVersion><!-- compiler-version --></compilerVersion> 
     </configuration> 
     </plugin> 
    </plugins> 
    [...] 
    </build> 
    [...] 
</project> 

避免Java路徑的硬編碼使其可執行如下。

<executable>${JAVA_1_5_HOME}/bin/javac</executable> 

去你的服務器將Settings.xml並創建一個配置文件象下面這樣。

<settings> 
    [...] 
    <profiles> 
    [...] 
    <profile> 
     <id>compiler</id> 
     <properties> 
      <JAVA_1_5_HOME>C:\Program Files\Java\j2sdk1.5.2_09</JAVA_1_5_HOME> 
     </properties> 
    </profile> 
    </profiles> 
    [...] 
    <activeProfiles> 
    <activeProfile>compiler</activeProfile> 
    </activeProfiles> 
</settings> 

它會幫助你檢測您的JAVA_HOME

相關問題