英文:
Change maven default java compliance level for new projects
问题
我正在使用Eclipse IDE 2020-03。每当我创建一个Maven项目时,其默认的Java兼容级别总是1.7。我的JDK版本是11。
可以通过以下步骤手动将Java兼容级别设置为11。
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
我的关注点是,每次我创建新的Maven项目时都必须设置这个配置。
是否有任何解决方案可以将新Maven项目的默认Java兼容性设置为我系统中安装的JDK版本(这里是JDK 11)?
另外,如果我想将这个JDK为11的Maven项目发送到另一个JDK版本为8的系统,它能在另一个系统上运行吗?
英文:
I am using Eclipse IDE 2020-03. Whenever I created a maven project its default java compliance level is always 1.7. My JDK version is 11.
It is possible to set java compliance to 11 manually by following.
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
My concern is that I have to set this configuration everytime I create a new maven project.
Is there any solution where default java compliance of new maven project is set to my JDK version (here JDK 11) installed in my system?
Also I need some guidance about if I want to send this maven project whose JDK is 11 to other system where the JDK version is 8, will it work on other system?
答案1
得分: 1
Java编译所需的版本需要在您的POM中设置。
如果您有许多项目,您可以为所有这些项目创建一个父POM,然后从中继承。
如果版本级别高于已安装的JDK(假设您想在JDK 1.8上编译为Java 11),构建将失败。
另一方面,使用JDK 14编译适用于Java 11是可以的。
英文:
The Java version you compile for needs to be set somewhere in your POM.
If you have many projects, you can create a parent POM for all of those from which you inherit.
If the level is greater than the installed JDK (say you want to compile for Java 11 on a JDK1.8), the build will fail.
On the other hand, it is fine to e.g. compile for Java 11 with a JDK 14.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论