![](/img/trans.png)
[英]VSCode Maven error `The compiler compliance specified is 1.7 but a JRE 13 is used`
[英]Where is the JDK version to be used by Maven compiler specified?
当我没有在我的pom.xml文件中定义如下内容时,在我的系统中为Maven定义了在编译时使用哪个版本的Java JDK(我的系统上安装了多个版本, JAVA_HOME
指向其中一个版本) ?
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
</plugins>
</build>
Maven医生说
Compiler Plugin用于编译项目的源代码。 默认编译器是javac,用于编译Java源代码。 另请注意, 目前默认的源设置为1.5,默认目标设置为1.5,与您运行Maven的JDK无关。 如果要更改这些默认值,则应设置源和目标,如设置Java编译器的
-source
和-target
中所述。
参考: http : //maven.apache.org/plugins/maven-compiler-plugin/index.html
Maven的Jira Change默认源级别为1.5,这个有趣的线程
编辑:
Maven 3.0及更高版本的更新:
Compiler Plugin用于编译项目的源代码。 从3.0开始,默认编译器是javax.tools.JavaCompiler (如果您使用的是java 1.6)并且用于编译Java源代码。 如果要使用javac强制插件,则必须配置插件选项forceJavacCompilerUse。
资料来源: http : //maven.apache.org/plugins/maven-compiler-plugin/index.html
感谢nachteil指出它。
只需使用属性
<properties>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.test.skip>true</maven.test.skip>
</properties>
从maven编译器插件doucemntation:
从3.0开始,默认编译器是javax.tools.JavaCompiler(如果您使用的是java 1.6)并且用于编译Java源代码。 如果要使用javac强制插件,则必须配置插件选项forceJavacCompilerUse。
我通过搜索引擎找到了这篇文章,我觉得值得更新。 另外: -target
和-source
选项不会影响编译器本身,而是影响源代码处理和生成输出字节代码的方式。
您必须在maven setting.xml文件中定义属性。 该属性是您的第二个javac路径。(D:\\ dev \\ java \\ ibm \\ java1.6.0 \\ bin \\ javac)在pom文件中将此属性用于maven-compiler-plugin之后。
Setting.xml的
<settings>
<profiles>
<profile>
<id>IBM_JAVA</id>
<properties>
<IBM_JAVA_1_6_JAVAC>D:\dev\java\ibm\java1.6.0\bin\javac</IBM_JAVA_1_6_JAVAC>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>IBM_JAVA</activeProfile>
</activeProfiles>
</settings>
的pom.xml
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<executable>${IBM_JAVA_1_6_JAVAC}</executable>
<encoding>UTF-8</encoding>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.