2

Possible Duplicate:
Maven Install: “Annotations are not supported in -source 1.3”

I use ubuntu 10.04 and open-jdk-1.6.0.

This is my mvn -version output:

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"

But when I run mvn test, there are some errors:

/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

I seems that the mvn thought I use java 1.3, perhaps it just support java 1.5?

Community
  • 1
  • 1
unionx
  • 437
  • 3
  • 15

3 Answers3

14

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

How do I set up Maven so it will compile with a target and source JVM of my choice? You must configure the source and target parameters in your pom. For example, to set the source and target JVM to 1.5, you should have in your 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>
...
Chris Nava
  • 6,614
  • 3
  • 25
  • 31
  • I add this snippet to my pom.xml and it worked. I think I should check maven's doc. Thank you. – unionx Dec 14 '11 at 06:17
  • Please mark this (or another) answer as the solution. It helps keep the "best" answer easy to find. – Chris Nava Dec 14 '11 at 19:39
  • On windows works without this. different defaults? why i wonder? – tgkprog Jul 24 '15 at 20:23
  • If you are using an IDE, then it may be using internal settings when it compiles (for example based on your .classpath file in Eclipse.) In such an instance the code generated by the IDE will differ from that generated by the maven CLI and could cause you problems if your build process runs outside the IDE. – Chris Nava Jul 25 '15 at 04:54
1

Check your POM file. You've probably got a plugin config for the compiler plugin telling Maven to use Java 1.3. See this page for details.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
1

check your POM file and add your compiler version like below.

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

to avoid Hard coding of java path make it executable like below.

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

go to your server Settings.xml and create a profile like below.

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

it will help you to detect your JAVA_HOME.

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90