如何为Maven指定特定的JDK版本来构建我的项目? [英] How to appoint specific jdk version for maven to build my project?

查看:819
本文介绍了如何为Maven指定特定的JDK版本来构建我的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:测试用例在本地为绿色,但由于不支持的jdk版本,因此在hudson服务器上失败了.本地是ibm jdk1.6 sr4窗口,但是hudson服务器在ibm jdk1.6 sr9 linux上安装了. 不支持将此Java虚拟机与Blaze Advisor一起使用,因为java.beans.Introspector的实现未能通过验证."

My problem is: Test cases are green on local, but some are failed on hudson server because of non-supported jdk version. Local is ibm jdk1.6 sr4 windows, but hudson server installed ibm jdk1.6 sr9 linux. "This Java virtual machine is not supported for use with Blaze Advisor because the implementation of java.beans.Introspector failed to pass validation."

有人告诉我,哈德森服务器无法更改为其他jdk,所以我认为是否有任何解决方法可以绕过这些故障? 我可以告诉Maven使用特定的jdk编译项目吗?像是sr4而不是sr9的1.6版本.另外我还需要Maven作为依赖项下载sr4,因为服务器上没有此版本.

I was told Hudson server cannot change to other jdk, so I am think is there any work around to bypass those failure? Can I tell maven to compile project with specific jdk? Like, 1.6 version with sr4, instead of sr9. Also I need maven to download sr4 as dependency coz there is no this version on server.

在我搜索时似乎很难做到这一点.那我还有什么选择呢?

Seems it's hard to do this as I searched out. So what else option i could have?

感谢您的任何建议.

推荐答案

如果需要使用其他版本,Maven应该以JAVA_HOME中指定的Java开头.它将要求该版本已经安装在服务器上.

Maven should start with the java specified in JAVA_HOME if you need to use a different version I would use the toolchain plugin to run your build with a specified jdk version. It will require the version be already installed on the server though.

http://maven.apache.org/guides/mini/guide-using-toolchains.html

您需要将插件添加到pom并添加一个toolchains.xml文件.

You will need to add the plugin to your pom and add a toolchains.xml file.

  <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>

toolchains.xml文件添加到.m2文件夹中,该文件指定jdk的安装位置

toolchains.xml file added to .m2 folder which specifies the install location for the jdk

<?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>/path/to/jdk/1.5</jdkHome>
     </configuration>
  </toolchain>

这篇关于如何为Maven指定特定的JDK版本来构建我的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆