使用maven编译java版本

发布于 2024-12-20 21:15:36 字数 523 浏览 5 评论 0原文

我有一段用java版本1.5编译的代码(在maven编译插件上源和目标都设置为1.5)

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

我现在想做的是为应用程序编译它们(源是一个插件主应用程序)升级到 java 版本 1.6

在这种情况下;

我需要使用带有参数的编译插件吗?

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

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

加上;我是否需要设置 java home 和 java 1.6 的路径,否则插件将使用正确的工件(可能是通过下载)来编译 java 1.6 ?

问候..

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 )

<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

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

regards..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

失退 2024-12-27 21:15:36

首先,您绝对不必在 Java 1.6 上重新编译。当由在 Java 1.6 平台上运行的 Java 1.6 应用程序使用时,使用 Java 1.5 编译的 Maven 工件可能会正常工作。

如果您确实想重新编译,那么任一组合都应该有效。事实上,它们在所有意图和目的上都是相同的,因为 Java 1.5 和 1.6 之间的语言没有相关的变化。然而,在 Java 1.6 上编译和运行单元测试是有价值的……以防某些库更改导致您的代码在新平台上失败。

First of all, you don't absolutely have to recompile on 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.

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

我的鱼塘能养鲲 2024-12-27 21:15:36

您应该在 JAVA_HOME 中使用 Java 1.6,并且如果您在 1.5 中使用目标/源,那么您的插件应该运行,而这应该在 1.6 中运行。除非您使用 Java 1.6 中的特定内容(例如 String.isEmpty())...

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. Except if you are using particular things from Java 1.6 (String.isEmpty() for example)...

女中豪杰 2024-12-27 21:15:36

始终在 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>

Always set source and target in your pom.xml file

<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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文