0

Can anyone help me with this issue? It seems that when I run mvn -v command from command line directly from windows the command works as expected.

When I run mvn -v command from Jenkins build I got the following error.

The JAVA_HOME environment variable is not defined correctly 
This environment variable is needed to run this program 
NB: JAVA_HOME should point to a JDK not a JRE 

JAVA_HOME env is set to : C:\Program Files\Java\jdk1.8.0_144\bin I also tried without \bin but it's not working. %JAVA_HOME% is added also in Path

Thanks.

user3664679
  • 19
  • 1
  • 4
  • 2
    The JAVA_HOME should be without `bin` directory. Afterwards you have to reopen the console otherwise the environment variables will not being set...(updated). If you run Jenkins on Windows you have to restart Jenkins as well otherwise it will not recognize the enviornment variable change. I recommend to use the global tools configuration in Jenkins instead of environment variables.. – khmarbaise Mar 09 '20 at 15:11
  • It seems that mvn -v command is executed from jenkins interface remotely on another machine via Execute Windows batch command ( so i suppose it's using the java_home from this another machine) or am I wrong? – user3664679 Mar 09 '20 at 15:25
  • You are wrong. If Jenkins is running on a remote node it's using the configuration via global tools configuration which should be done correctly.... – khmarbaise Mar 09 '20 at 18:20
  • From what I saw, on jenkins server java -version command is returning openjdk version "1.8.0_201-1-ojdkbuild". When executing a Windows batch command from jenkins in this case java -version to another machine it's returning : java version "1.8.0_144" 16:18:15 Java(TM) SE Runtime Environment (build 1.8.0_144-b01). Global Tool Configuration for jenkins is: c:\Program Files\ojdkbuild\java-1.8.0-openjdk-1.8.0.201-1\ – user3664679 Mar 10 '20 at 08:12

1 Answers1

0

Looks like your Jenkins instance is unable to find local system's environment variable "JAVA_HOME".

Try providing the environment variable in the command itself with "mvn -DJAVA_HOME=C:\Java\jdk1.8.0\bin -v"

For long term fix, define system or user variables for JAVA_HOME or inject environment variable manually inside Jenkins.

Prasad Tamgale
  • 325
  • 1
  • 12
  • tried also with: mvn -DJAVA_HOME=C:\Java\jdk1.8.0\bin -v but i got the same error :( – user3664679 Mar 12 '20 at 08:58
  • Can you try the second option of injecting the environment variables manually? There should be an open of "Inject environment variable" in the job configuration or inject globally from Configure System option – Prasad Tamgale Mar 13 '20 at 11:29
  • Also check if JAVA_HOME is not getting overridden from pom.xml different from environment variables – Prasad Tamgale Mar 13 '20 at 11:48