jenkins jdk版本问题报错

maven3.2版本以后,运行maven必须使用JDK1.6以上的版本。maven3.0/maven3.1可以运行在JDK1.5版本上。


在做平台定制项目时,使用客户的开发环境:JDK1.6,MAVEN3.2.2,此时如果编译平台组件可能会有问题。例如:


PTP项目必须使用JDK1.5版本编译,因为1.6版本相比很多接口类增加了接口,在切换到JDK1.6后很多类将会无法编译通过。


解决方法:

使用maven提供的插件:maven-toolchains-plugin


maven-toolchains-plugin

The Maven Toolchains provide a way for plugins to discover what JDK (or other tools) are to be used during the build, without the need to configure them. With toolchains, a project can now be built using a specific version of JDK independent from the one Maven is running with.

maven-toolchains-plugin支持在2.09版本以上的maven环境使用。


使用方式,以ptp编译举例:

在pom-java.xml中编辑如下:



……
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-toolchains-plugin</artifactId>
<version>1.0</version>
<executions>
 <execution>
<phase>validate</phase>
<goals>
 <goal>toolchain</goal>
</goals>
 </execution>
</executions>
<configuration>
 <toolchains>
<jdk>
 <version>1.5</version>
 <vendor>sun</vendor>
</jdk>
 </toolchains>
</configuration>
</plugin>
<plugins>
……


maven-toolchains-plugin在这里指定使用的是sun提供的jdk1.5版本。在pom里面指定使用的jdk类型,还需要为maven增加一个配置文件,告诉maven该jdk工具存放路径。

我们需要配置toolchains.xml供maven读取,例如:



<?xml version="1.0" encoding="UTF8"?>
<toolchains>
 <toolchain>
    <type>jdk</type>
    <provides>
        <version>1.5</version>
        <vendor>sun</vendor>
        <id>default</id>
    </provides>
    <configuration>
       <jdkHome>D:/JDK1.5.22</jdkHome>
    </configuration>
 </toolchain>
 <toolchain>
    <type>jdk</type>
    <provides>
        <version>1.6</version>
        <vendor>sun</vendor>
        <id>ide</id>
    </provides>
    <configuration>
       <jdkHome>D:/jdk1.6.0_45-b06</jdkHome>
    </configuration>
 </toolchain>
</toolchains>


示例toolchains.xml中配置了2个jdk,在maven执行编译时,会根据type,version,vendor自动匹配,找到需要使用的工具路径。

toolchains.xml放在${用户目录}/.m2下,maven运行时自动加载。也可以通过命令行传递参数方式指定toolchains.xml文件路径。

命令行使用方式:mvn后传递-t参数,参数后跟toolchains.xml完整路径,例如:


mvn -X -t e:\maven\CSVW1\build\.m2\toolchains.xml clean install

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值