Maven报错Please ensure you are using JDK 1.4 or above and not a JRE
在部署Jenkins项目时,用Jenkins调用服务器上脚本时,脚本在服务器上执行没有任何问题,但是在Jenkins上调用时就报错,提示mvn应该使用全路径执行,当加入jdk,jre,maven环境变量时,出现下面错误。
[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环境变量即可。
#!/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可查询环境变量的家目录
您的资助是我最大的动力!
金额随意,欢迎来赏!