maven java 1.7,Maven无法使用1.7 JDK编译Java 7

I must be the anti-Maven since every time I try to use it I spend a lot of time struggling and then just give up. My latest is I can not compile Java 7 source code despite having a 1.7 JDK.

Here is the output of mvn compile. The interesting thing is that when I was using Maven 3.0.4, the error message said -source 1.5 instead of -source 1.6 with Maven 3.2.1

[ERROR] .../src/main/java/pox/common/ServiceResponse.java:[300,43] diamond operator is not supported in -source 1.6

[ERROR] (use -source 7 or higher to enable diamond operator)

[ERROR] .../src/main/java/pox/common/ServiceRequest.java:[185,43] diamond operator is not supported in -source 1.6

[ERROR] (use -source 7 or higher to enable diamond operator)

As you can see I am using a recent version of Maven and Maven is using Java 1.7.

$ mvn -v

Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-14T12:37:52-05:00)

Maven home: /usr/local/maven

Java version: 1.7.0_40, vendor: Oracle Corporation

Java home: /usr/local/jdk1.7.0_40-x64/jre

Default locale: en_US, platform encoding: UTF-8

OS name: "linux", version: "2.6.18-371.4.1.el5", arch: "amd64", family: "unix"

I think the mvn script is adding the /jre since my environment variable does not specify it.

$ echo -e "$JAVA_HOME\n$M2_HOME"

/usr/local/java7-x64

/usr/local/maven

$ which javac

/usr/local/java7-x64/bin/javac

I was writing some POJOs that I wanted to Springify so I decided to use Maven and found this getting started with Maven on the Spring site.

I copied the pom.xml and source from the site into my STS/Eclipse project that only contained Java source and tried to compile. STS has no problem compiling any of the source code in src/main/java. I can remove the code that is dependent on Java 1.7 and get Maven to compile.

Every thing I have found so far implies I do not have my JAVA_HOME set correctly but I am pointing to a 1.7 JDK.

解决方案

Well I had a similar problem, I had a project with maven and eclipse but there were problems to compile because the default level source of maven was java 1.5 and of course my code was in java 1.6, so i had to add the compiler plugin of maven to set the right version of my source of code, here is my configuration, so I guess you should change only the 1.6 to 1.7

org.apache.maven.plugins

maven-compiler-plugin

3.1

1.6

1.6

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值