简体   繁体   English

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

[英]Jenkins maven Unable to locate the Javac compiler in JDK

Problem : Unable to build spring maven project using Jenkins with JDK 1.8 问题:无法使用Jenkins和JDK 1.8来构建spring maven项目

Description : Im using Jenkins to build my spring project managed by Maven.I have configured Java 1.7 and 1.8 in Jenkins using the JDK Installations options. 说明 :即时通讯使用詹金斯建立由Maven.I管理我的春天项目已使用JDK的安装选项詹金斯配置的Java 1.7和1.8。 when selecting Java 1.7 in the build configuration and running the build, build process is success. 在构建配置中选择Java 1.7并运行构建时,构建过程成功。 But when i select Java 1.8 in the build configuration and running the build, build process gets failed. 但是,当我在构建配置中选择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. 我还使用Java 1.7手动运行了Maven,没有发现任何问题。 But when i ran the same with Java 1.8 and redirected the output to file, found the below error 但是当我对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 variable is correctly pointing to the JDK 1.8 installation home directory and the bin folder is also added to the path JAVA_HOME变量正确指向JDK 1.8安装主目录,并且bin文件夹也已添加到路径

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

When changed the JAVA_HOME variable to point to Java 1.7, build is running normally and no errors 将JAVA_HOME变量更改为指向Java 1.7时,构建正常运行并且没有错误

Root Cause 根本原因

when debugged, it ended up in the file JavacCompiler.java of artifact plexus-compiler-javac. 调试后,它最终出现在工件plexus-compiler-javac的JavacCompiler.java文件中。 The line System.getProperty( "java.home" ) in the compile process outputs differently for Java 8 and Java 7 编译过程中的System.getProperty(“ java.home”)行对于Java 8和Java 7的输出有所不同

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

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

Worked Solution : 可行的解决方案:

Re-installation of Java 8 重新安装Java 8

通过cmd启动从属服务器,但不要键入"java -jar slave.jar ....." ,而是将java.exe的完整路径提到为"C:\\Program Files\\Java\\jdk1.8.0_121\\bin\\java.exe" -jar slave.jar ......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM