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

时间:2016-01-13 08:40:32

标签: 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并运行构建时,构建过程就会失败。

  

****以下是jenkins控制台输出****

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

*

  

我还使用Java 1.7手动运行Maven,并且没有观察到任何问题。但   当我使用Java 1.8运行相同的程序并将输出重定向到文件时,   发现以下错误

*

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文件夹也添加到路径

echo%JAVA_HOME%导致C:\ DevEnv \ ProgramFiles \ Java \ jdk1.8.0_20

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

2 个答案:

答案 0 :(得分:0)

  

根本原因

调试时,它最终出现在神器plexus-compiler-javac的JavacCompiler.java文件中。编译过程中的System.getProperty(&#34; java.home&#34;)行对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

  

工作解决方案:

重新安装Java 8

答案 1 :(得分:0)

通过cmd启动奴隶,但不要输入"java -jar slave.jar .....",而是将java.exe的完整路径称为"C:\Program Files\Java\jdk1.8.0_121\bin\java.exe" -jar slave.jar ......