java - Jenkins maven无法在JDK中找到Javac编译器

标签 java maven jenkins build compiler-errors

问题:无法使用Jenkins和JDK 1.8来构建spring maven项目

描述:我使用Jenkins来构建由Maven管理的spring项目。我已经使用JDK Installations选项在Jenkins中配置了Java 1.7和1.8。在构建配置中选择Java 1.7并运行构建时,构建过程成功。但是,当我在构建配置中选择Java 1.8并运行构建时,构建过程将失败。

****Below is the jenkins console output****


Started by user anonymous
Building in workspace C:\Users\anonymous\.jenkins\jobs\springsecuritysampleproject1\workspace
Updating file:///C:/DevEnv/Repositories/LocalSVNServerRepo/root/springsecuritysample/trunk at revision '2016-01-13T13:35:52.488 +0530'
U         src\main\java\org\springframework\security\sample\HomeController.java
At revision 21
Parsing POMs
[workspace] $ C:\DevEnv\ProgramFiles\Java\jdk1.8.0_20/bin/java -cp C:\Users\anonymous\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-agent-1.5.jar;C:\DevEnv\ProgramFiles\ProjectTools\Apache_Maven_3.3.3\boot\plexus-classworlds-2.5.2.jar;C:\DevEnv\ProgramFiles\ProjectTools\Apache_Maven_3.3.3/conf/logging jenkins.maven3.agent.Maven31Main C:\DevEnv\ProgramFiles\ProjectTools\Apache_Maven_3.3.3 C:\Users\anonymous\.jenkins\war\WEB-INF\lib\remoting-2.53.2.jar C:\Users\anonymous\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven31-interceptor-1.5.jar C:\Users\anonymous\.jenkins\plugins\maven-plugin\WEB-INF\lib\maven3-interceptor-commons-1.5.jar 52876
<===[JENKINS REMOTING CAPACITY]===>channel started
Executing Maven:  -B -f C:\Users\anonymous\.jenkins\jobs\springsecuritysampleproject1\workspace\pom.xml install
Waiting for Jenkins to finish collecting data
[JENKINS] Archiving C:\Users\anonymous\.jenkins\jobs\springsecuritysampleproject1\workspace\pom.xml to org.springframework.security/sample/1.0.0-BUILD-SNAPSHOT/sample-1.0.0-BUILD-SNAPSHOT.pom
Sending e-mails to: test@test.com
channel stopped
Archiving artifacts
Sending e-mails to: test@test.com
Finished: FAILURE

*

I also ran Maven manually with Java 1.7 and no issues observerd. But when i ran the same with Java 1.8 and redirected the output to file, found the below error



*
INFO] Compiling 1 source file to C:\DevEnv\STSWorkspaces\springsecuritysample\target\classes
[INFO] -------------------------------------------------------------
**[ERROR] COMPILATION ERROR :** 
[INFO] -------------------------------------------------------------
[ERROR] Unable to locate the Javac Compiler in:
  C:\DevEnv\ProgramFiles\Java\jdk1.8.0_20\..\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.
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.640 s
[INFO] Finished at: 2016-01-13T13:40:34+05:30
[INFO] Final Memory: 8M/487M
[INFO] ------------------------------------------------------------------------

JAVA_HOME变量正确指向JDK 1.8安装主目录,并且bin文件夹也添加到路径中

回声%JAVA_HOME%结果在C:\ DevEnv \ ProgramFiles \ Java \ jdk1.8.0_20

将JAVA_HOME变量更改为指向Java 1.7时,构建正常运行且没有错误

最佳答案

Root Cause



调试后,它最终出现在 Artifact plexus-compiler-javac的JavacCompiler.java文件中。编译过程中的System.getProperty(“java.home”)行对于Java 8和Java 7的输出有所不同

Java 7-C:\ DevEnv \ ProgramFiles \ Java \ jdk1.7.0_80 \ jre

Java 8-C:\ DevEnv \ ProgramFiles \ Java \ jdk1.8.0_20

Worked Solution :



重新安装Java 8

关于java - Jenkins maven无法在JDK中找到Javac编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34761896/

相关文章:

django - Jenkins Cobertura 插件 "Source code is unavailable"

docker - 如何在 docker 中访问/var/jenkins_home?

Java递归求补集的方法

java - 我不能映射/flatMap 一个 OptionalInt 吗?

windows-7 - 无法使用 tomcat-maven-plugin 从另一台计算机(windows 7)部署到 tomcat 7(在 windows 7 计算机上)

java - Maven Spring 项目给我 org.slf4j.spi.LocationAwareLogger 错误

java - 简单程序中setListAdapter出错

java - Java中的for循环是如何构造的?

java - frontend-maven-plugin 执行两次

linux - 在Docker文件中使用pip安装AWS CLI