Maven報錯Please ensure you are using JDK 1.4 or above and not a JRE

在部署Jenkins項目時,用Jenkins調用服務器上腳本時,腳本在服務器上執行沒有任何問題,可是在Jenkins上調用時就報錯,提示mvn應該使用全路徑執行,當加入jdk,jre,maven環境變量時,出現下面錯誤。java

 

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project kpl-model: Compilation failure
[ERROR] Unable to locate the Javac Compiler in:
[ERROR]   /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.171-8.b10.el6_9.x86_64/jre/../lib/tools.jar
[ERROR] Please ensure you are using JDK 1.4 or above and
[ERROR] not a JRE (the com.sun.tools.javac.Main class is required).
[ERROR] In most cases you can change the location of your Java
[ERROR] installation by setting the JAVA_HOME environment variable.
[ERROR] 

而maven編譯須要jdk做爲運行環境。
所以,咱們只要設置爲jdk便可,去掉jre環境變量便可。apache

#!/bin/bash
export JAVA_HOME=/usr/local/jdk
export M2_HOME=/opt/apache-maven
export PATH=$JAVA_HOME/bin:$PATH
export PATH=${M2_HOME}/bin:${PATH}
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

注:使用which java,mvn -v可查詢環境變量的家目錄bash

相關文章
相關標籤/搜索