我已将我的 Web 应用程序升级到 Java 7,JAVA_HOME 指向 1.7。我的 Maven 插件正在从 java_home 读取 Java 版本。但是在 pom.xml 中看到以下设置后我有点困惑:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<fork>true</fork>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
如果我保持上面的设置不变,Maven 会用 1.6 还是 1.7 编译 Java 代码?根据我的理解,基于 this link ,以上设置将获得优先权,项目将使用 1.6 而不是 1.7 进行编译。对吗?
如果我提供如下设置并且我有特定于 JDK 1.7 的代码,我的代码现在可以编译吗?
<source>1.6</source>
<target>1.7</target>
我不确定;上面的设置到底是什么意思?
没有插件的编译器配置
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
javac -帮助
javac -help
-source <release> Provide source compatibility with specified release
-target <release> Generate class files for specific VM version
source
Specifies the version of source code accepted. The following values for release are allowed:
- 1.6 No language changes were introduced in Java SE 6. However, encoding errors in source files are now reported as errors instead of warnings as in previous releases of Java SE.
- 6 Synonym for 1.6.
- 1.7 This is the default value. The compiler accepts code with features introduced in Java SE 7.
- 7 Synonym for 1.7.
target
Generate class files that target a specified version of the VM. Class files will run on the specified target and on later versions, but not on earlier versions of the VM. Valid targets are 1.1, 1.2, 1.3, 1.4, 1.5 (also 5), 1.6 (also 6), and 1.7 (also 7).
The default for -target depends on the value of -source:
兼容性