java 源和目标的 Maven 编译器插件 jdk 版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29473995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Maven compiler plugin jdk versions for source and target
提问by Ilya Zinkovich
I have the following configuration in my pom.xml for maven-compiler-plugin.
我的 pom.xml 中有以下配置用于 maven-compiler-plugin。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
What should be the source and target version of jdk? How it depends on version of jdk installed on my computer? May they be different? e.g. installed jdk is 1.8, in source parameter - 1.6, target - 1.7.
jdk的源和目标版本应该是什么?它如何取决于我计算机上安装的 jdk 版本?它们可能不同吗?例如安装的 jdk 是 1.8,在源参数 - 1.6,目标 - 1.7。
回答by khmarbaise
With source/target you only define the switches of javac
which means to produce compatible code. For example if you have installed jdk 8 and would like to create java 7 runable classes.
But it does not check if you have installed a JDK 8 at all. This would also work if you have JDK 7 installed.
使用源/目标,您只需定义javac
生成兼容代码的方法的开关。例如,如果您已经安装了 jdk 8 并且想要创建 java 7 可运行类。但它根本不检查您是否安装了 JDK 8。如果您安装了 JDK 7,这也将起作用。
If you really need to check the JDK version which is installed you have to go via the maven-enforcer-pluginand check the installed JDK...
如果您确实需要检查已安装的 JDK 版本,则必须通过maven-enforcer-plugin并检查已安装的 JDK ...
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>enforce-java</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireJavaVersion>
<version>1.8.0</version>
</requireJavaVersion>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
With the above you are not able to build on a JDK 7 anymore...only with JDK 8...
有了上述内容,您将无法再在 JDK 7 上构建……只能使用 JDK 8……
BTW: Why are you using such an old maven-compiler-pluginversion ?
顺便说一句:你为什么使用这么旧的maven-compiler-plugin版本?