Jenkins / Maven:无法解析默认的 JAVA_HOME 路径,构建失败

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20270002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 00:44:18  来源:igfitidea点击:

Jenkins / Maven: Could not resolve default JAVA_HOME path, Build failing

javamavenjenkins

提问by mchlfchr

I've got a problem regarding Java Builds in Jenkins.

我在 Jenkins 中遇到了有关 Java 构建的问题。

The Error I resolve is the following one:

我解决的错误如下:

Unable to locate the Javac Compiler in: C:\Jenkins\jre\..\lib\tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.

Unable to locate the Javac Compiler in: C:\Jenkins\jre\..\lib\tools.jar Please ensure you are using JDK 1.4 or above and not a JRE (the com.sun.tools.javac.Main class is required). In most cases you can change the location of your Java installation by setting the JAVA_HOME environment variable.

I got JDK1.6and JDK1.7projects, so I need two JDK installations. For my default Java JDK I used the 1.6 for the JAVA_HOMEvariable, which points to C:\Program Files\Java\jdk1.6.0_45. Same for the 1.7 version, but in a separated variable (JAVA_HOME7). The PATHvariable contains the appended \binto the two JDK versions.

我有JDK1.6JDK1.7项目,所以我需要两个 JDK 安装。对于我的默认 Java JDK,我使用 1.6 作为JAVA_HOME变量,它指向C:\Program Files\Java\jdk1.6.0_45. 与 1.7 版本相同,但在一个单独的变量 ( JAVA_HOME7) 中。该PATH变量包含附加\bin到两个 JDK 版本。

In Jenkins I also added both versions for JDK and as helper variables. If I am setting a concrete version for a project (e.g. JDK1.7), then it's building without any issues. Unfortunately I've got a lot of build-projects, so it would be time consuming to set this manually.

在 Jenkins 中,我还为 JDK 和辅助变量添加了两个版本。如果我正在为一个项目(例如JDK1.7)设置一个具体的版本,那么它的构建没有任何问题。不幸的是,我有很多构建项目,因此手动设置它会很耗时。

I don't understand where the call or variable for the path of the error C:\Jenkins\jre\..\lib\tools.jaris set and where I can modify it...

我不明白错误路径的调用或变量在C:\Jenkins\jre\..\lib\tools.jar哪里设置以及我可以在哪里修改它...

Jenkins Version: 1.509.4

詹金斯版本:1.509.4

Any hints or advices how to solve this problem?

任何提示或建议如何解决这个问题?

回答by Sudharsan Srinivasan

I faced the same problem. The below steps solved the problem

我遇到了同样的问题。以下步骤解决了问题

1) Go to Manage Jenkins - Configure system

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

2) Add JAVA_HOME and its path in Global Properties - Environment Variables

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

3) Add JDK and path in JDK section

3)在JDK部分添加JDK和路径