简体   繁体   English

在Maven中使用Java编译版本

[英]Using java compile version with maven

I have a piece of code which has been compiled with java version 1.5 ( both source and target are set to 1.5 on maven compile plugin ) 我有一段代码已经用Java 1.5版进行了编译(在maven编译插件上源和目标都设置为1.5)

<source>1.5</source>
<target>1.5</target>

What I want to do now is to compile them for an application ( the source is a plug in for a main application )which is upgraded to java version 1.6 我现在想做的是将它们编译为一个应用程序(源是主应用程序的插件),该应用程序已升级到Java版本1.6

In this case; 在这种情况下;

do I need to use compile plugin with the parameters; 我需要使用带有参数的编译插件吗?

<source>1.5</source>
<target>1.6</target>

or 要么

<source>1.6</source>
<target>1.6</target>

plus; 加; do I need to set the java home and path to java 1.6 or plugin will use the correct artifacts ( may be by downloading ) to compile for java 1.6 ?? 我需要将java home和path设置为java 1.6吗,否则插件将使用正确的工件(可能通过下载)来为java 1.6编译?

regards.. 问候..

First of all, you don't absolutely have to recompile on Java 1.6. 首先,您不一定非要在Java 1.6上重新编译。 Your Maven artifacts compiled using Java 1.5 will probably work fine when used by a Java 1.6 application running on a Java 1.6 platform. 当由在Java 1.6平台上运行的Java 1.6应用程序使用时,使用Java 1.5编译的Maven工件可能会正常工作。

If you do want to recompile, then either combination should work. 如果您确实想重新编译,则任何一种组合都应该起作用。 In fact, they are for all intents and purposes identical since there were no relevant changes in the language between Java 1.5 and 1.6. 实际上,它们在所有意图和目的上都是相同的,因为Java 1.5和1.6之间的语言没有相关更改。 However, there is value in compiling and running the unit tests on Java 1.6 ... just in case some library change causes your code to fail on the newer platform. 但是,在Java 1.6上编译和运行单元测试很有价值……以防万一某些库更改导致您的代码在较新的平台上失败。

Always set source and target in your pom.xml file 始终在pom.xml文件中设置源和目标

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

You should use the Java 1.6 in your JAVA_HOME and your plugin should run if you use target/source with 1.5 this should run with 1.6. 您应该在JAVA_HOME中使用Java 1.6,并且如果将target / source与1.5一起使用,则插件应运行,而应该在1.6中运行。 Except if you are using particular things from Java 1.6 (String.isEmpty() for example)... 除非您使用的是Java 1.6中的特定功能(例如String.isEmpty())...

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

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