[Maven - Java Version] 如何设置Maven的Java版本或者使用不同的JDK版本编译

In pom.xml, defined this maven.compiler.source properties to tell Maven to use Java 8 to compile the project.

1. Maven Properties

Java 8

pom.xml
    <properties>
        <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> </properties> 
 

Java 7

pom.xml
    <properties>
        <maven.compiler.target>1.7</maven.compiler.target> <maven.compiler.source>1.7</maven.compiler.source> </properties>

2. Compiler Plugin

Alternative, configure the plugin directly.

pom.xml
    <build>
        <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.6.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> 
Copy

References

  1. Maven – Setting the -source and -target of the Java Compiler
  2. How to compile Maven project with different JDK version?

 

------使用和maven启动使用的jdk不同的jdk编译-----

https://maven.apache.org/plugins/maven-compiler-plugin/examples/compile-using-different-jdk.html

-----可以在settings.xml或者环境变量中配置JAVA_1_6_HOME这种类型的,然后在

build-->plugins--> <plugin>-->

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
    <configuration>
        <verbose>true</verbose>
        <fork>true</fork>
        <executable>${JAVA_1_6_HOME}/bin/javac</executable>
        <compilerVersion>1.3</compilerVersion>
    </configuration>
</plugin>

 

 

 

 

转载于:https://www.cnblogs.com/zienzir/p/9318236.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值