简体   繁体   English

OSX中的Maven继续使用Java 1.5进行编译

[英]Maven in OSX Keeps Compiling with Java 1.5

I have a code that I'm working on from 2 different location, a Win7 machine and an OSX. 我有一个要在2个不同位置(一个Win7机器和一个OSX)上工作的代码。

When worked on using Win7 machine, I don't need to bother about which java version that Maven compiles, I just need to set the PATH variable. 在使用Win7机器进行工作时,我不必担心Maven编译的Java版本,只需要设置PATH变量即可。 If I'm on Java 5, it compiles against Java 5, if I'm on Java 7, it compiles against Java 7. No problem there. 如果我使用Java 5,则可以针对Java 5进行编译;如果我使用Java 7,则可以针对Java 7进行编译。

Different case for my OSX machine. 我的OSX机器的情况不同。 Now this is the exact same set of codes. 现在这是完全相同的代码集。

My Java version 我的Java版本

[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> java -version
java version "1.7.0_60"
Java(TM) SE Runtime Environment (build 1.7.0_60-b19)
Java HotSpot(TM) 64-Bit Server VM (build 24.60-b09, mixed mode)

My Maven version 我的Maven版本

[Mac-Pro] ~/apache-maven/apache-maven-3.1.1/conf $
p01ntbl4nk> mvn -version
Apache Maven 3.1.1 (0728685237757ffbf44136acec0402957f723d9a; 2013-09-17 23:22:22+0800)
Maven home: /Users/p01ntbl4nk/apache-maven/apache-maven-default
Java version: 1.7.0_60, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_60.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.9.1", arch: "x86_64", family: "mac"

Both shows the same java version. 两者都显示相同的Java版本。 Java 7u60. Java 7u60。

But when I run mvn clean compile on my codes, I am getting this "try-with-resource is not supported in -source1.5" 但是,当我在代码上运行mvn clean compile时,我得到的是“ -source1.5不支持try-with-resource”

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project archival-client: Compilation failure
[ERROR] /Users/p01ntbl4nk/GitRepositories/GenericArchival/root/archival-client/src/main/java/org/si/genericArchival/client/App.java:[140,6] error: try-with-resources is not supported in -source 1.5
[ERROR] -> [Help 1]
[ERROR] 

I've checked, I don't have any reference in my main maven settings.xml or in any of the pom.xml in the modules that would indicate to use sourve version 1.5 我已经检查过,在我的主Maven settings.xml或模块中的任何pom.xml中都没有任何引用,表明要使用酸性版本1.5

To fix this, I would have to add the following to all my pom.xml 为了解决这个问题,我必须在我的所有pom.xml文件中添加以下内容

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
        <source>1.7</source>
        <target>1.7</target>
    </configuration>
</plugin>

But this would mean that the maven modules are no longer adaptable to the java version of the underlying platform. 但这意味着maven模块不再适用于基础平台的Java版本。

Am I missing anything? 我有什么想念的吗?

Well, you already have your answer, but here it is definitively. 好了,您已经有了答案,但是绝对可以。 http://maven.apache.org/plugins/maven-compiler-plugin/ http://maven.apache.org/plugins/maven-compiler-plugin/

Also note that at present the default source setting is 1.5 and the default target setting is 1.5, independently of the JDK you run Maven with. 还要注意,当前的默认源设置是1.5,默认目标设置是1.5,与运行Maven的JDK无关。 If you want to change these defaults, you should set source and target as described in Setting the -source and -target of the Java Compiler. 如果要更改这些默认值,则应按照设置Java编译器的-source和-target中所述设置源和目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM