我使用maven测试来运行我的项目,但它说我使用的是JDK 1.3

时间:2011-12-14 05:26:21

标签: java maven openjdk

  

可能重复:
  Maven Install: “Annotations are not supported in -source 1.3”

我使用的是ubuntu 10.04和open-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 test时,有一些错误:

/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?

3 个答案:

答案 0 :(得分:14)

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

答案 1 :(得分:1)

检查您的POM文件。您可能已经获得了编译器插件的插件配置,告诉Maven使用Java 1.3。有关详细信息,请参阅this page

答案 2 :(得分: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

相关问题