Maven无法使用1.7 JDK编译Java 7 [英] Maven Won't Compile Java 7 with 1.7 JDK

查看:267
本文介绍了Maven无法使用1.7 JDK编译Java 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.

这是mvn compile的输出.有趣的是,当我使用Maven 3.0.4时,错误消息显示-source 1.5而不是Maven 3.2.1的-source 1.6

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)

如您所见,我正在使用最新版本的Maven,而Maven正在使用Java 1.7.

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"

由于我的环境变量未指定mvn脚本,因此我认为mvn脚本正在添加/jre.

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

我正在编写一些我想进行 Springify 的POJO,所以我决定使用Maven,并在Spring网站上找到了Maven入门.

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.

http://docs.spring .io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#getting-started

我从站点复制了pom.xml和源代码到我的STS/Eclipse项目中,该项目仅包含Java源代码并试图进行编译. STS编译src/main/java中的任何源代码都没有问题.我可以删除依赖Java 1.7的代码,并让Maven进行编译.

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.

到目前为止,我发现的所有内容都意味着我没有正确设置JAVA_HOME,但是我指向的是1.7 JDK.

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.

推荐答案

我有一个类似的问题,我有一个带有maven和eclipse的项目,但是存在编译问题,因为maven的默认级别源是Java 1.5及以下版本.当然我的代码在Java 1.6中,所以我必须添加maven的编译器插件来设置我的代码源的正确版本,这是我的配置,所以我想您应该只将1.6更改为1.7

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

<build>
    <plugins>
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.1</version>
          <configuration>
            <source>1.6</source>
            <target>1.6</target>
          </configuration>
        </plugin>
    </plugins>
</build>

这篇关于Maven无法使用1.7 JDK编译Java 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆