Maven在Jenkins执行时使用了不正确的Java版本 [英] Maven uses an incorrect Java version when it is executed by Jenkins

查看:884
本文介绍了Maven在Jenkins执行时使用了不正确的Java版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些使用Maven和Jenkins编译和部署的项目,他们已经工作正常,直到现在我已经将java版本从6更改为7.

I have some projects compiled and deployed with Maven and Jenkins and they have worked fine until now that I have changed the java version from 6 to 7.

为此,我执行了命令 sudo update-alternatives --config javac 并更改了 / etc / profile 文件中的JAVA_HOME和PATH的值。我还修改了pom文件,因此它使用jdk 1.7:

In order to do this I executed the command sudo update-alternatives --config javac and changed the values of JAVA_HOME and PATH in the /etc/profile file. I have also modified the pom file so it uses jdk 1.7:

<properties>
    ...
    <jdk.version>1.7</jdk.version>
</properties>

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
        ...
        <configuration>
            <source>${jdk.version}</source>
            <target>${jdk.version}</target>
        </configuration>
</plugin>

当我在控制台上执行它们时,它们编译正常,显示的版本是正确的:

When I execute them on the console they compile fine and the displayed version is correct:

javac -version
javac 1.7.0_55

mvn install -debug
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.7.0_55
Java home: /usr/lib/jvm/java-7-openjdk-amd64/jre

然而,当我在jenkins工作中做同样的事情时,Maven使用的是1.6版本而不是1.7版本:

However, when I do the same in a jenkins job, Maven uses the 1.6 version instead of 1.7:

javac -version
javac 1.7.0_55

mvn install -debug
Apache Maven 2.2.1 (rdebian-8)
Java version: 1.6.0_31
Java home: /usr/lib/jvm/java-6-openjdk-amd64/jre

我还修改了用于指示新版本的maven配置文件,在Jenkins管理面板中我更改了JDK版本。但是,Maven仍在使用1.6 jdk。

I have also modified the maven configuration file that I use to indicate the new version, and in the Jenkins administration panel I have changed the JDK version. However, Maven is still using the 1.6 jdk.

你知道我怎么能改变它?

Do you know how can I change it?

推荐答案

我找到了解决方案此处
有必要在Jenkins的全局配置中定义JAVA_HOME变量。
正如Sudharsan解释的那样,步骤是:

I found the solution here. It is necessary to define the JAVA_HOME variable also in the global configuration of Jenkins. As Sudharsan explained, the steps are:


  1. 转到管理Jenkins - 配置系统

  1. Go to Manage Jenkins - Configure system

在全局属性中添加JAVA_HOME及其路径 - 环境变量

Add JAVA_HOME and its path in Global Properties - Environment Variables

这篇关于Maven在Jenkins执行时使用了不正确的Java版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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