Jenkins fails to start on Windows Server after Java Runtime update uninstalled older version of JRE

0

I have a Jenkins Server running on Windows Server 2012 and Java prompted me to update to a newer version (jre1.8.0_261 to jre1.8.0_271) and during that install it asked to uninstall older versions (for security reasons) which I allowed it to do. When I restarted Jenkins service it failed to restart. Error log indicates this Informational message:

Starting C:\Program Files\Java\jre1.8.0_261\\bin\java.exe -Xrs -Xmx256m -Dhudson.lifecycle=hudson.lifecycle.WindowsServiceLifecycle -jar "C:\Program Files\Jenkins\jenkins.war" --httpPort=8080 --webroot="C:\Windows\system32\config\systemprofile\AppData\Local\Jenkins\war"

And this error:

Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo) at winsw.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary2 envVars, String workingDirectory, Nullable1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler, Boolean hideWindow) at winsw.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin) at winsw.WrapperService.OnStart(String[] args) at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

The informational message gave me a clue to the problem: Jenkins is pointing to the older version of Java location here: C:\Program Files\Java\jre1.8.0_261

However the folder is empty, most importantly there is no bin folder present (no doubt due to the aforementioned uninstall).

The newer version here has the full java binaries: C:\Program Files\Java\jre1.8.0_271

How do you get Jenkins to point to the new JRE?

windows-server-2012-r2
java
jenkins
asked on Server Fault Oct 23, 2020 by Jeff Mergler

2 Answers

1

There is a pretty simple solution: locate the Jenkins.xml file (for me its located at C:\Program Files\Jenkins\jenkins.xml) and edit it.

Locate the <executable> element and correct it so that it points to the new JRE path, for example in my case I changed

this <executable>C:\Program Files\Java\jre1.8.0_261\bin\java.exe</executable>

to this <executable>C:\Program Files\Java\jre1.8.0_271\bin\java.exe</executable>

Save file and Jenkins starts up fine now.

answered on Server Fault Oct 23, 2020 by Jeff Mergler
0

Refer to @Jeff Mergler's answer for primary sol'n.

We get around the whole problem by using a link. mklink /D C:Java\jre1.8 C:\Program Files\Java\jre1.8.0_261, and place that in the jenkins.xml. We install jdk manually first, then just stop all our apps, repoint the one link and start all our apps. Then remove old jdk. We also have a link for 8 and one for 11. We do the same on the linux side, where we lifted the solution from!

Also, based on Oracle's new licensing terms, you should be using something like adoptOpenJDK to not run afoul of Big Red's terms.

eg:

C:\Tools\Java>echo %JAVA_HOME%
C:\Tools\Java\jdk

C:\Tools\Java>dir
 Volume in drive C is L103437
 Volume Serial Number is 28B0-4574

 Directory of C:\Tools\Java

2020-10-28  12:43 PM    <DIR>          .
2020-10-28  12:43 PM    <DIR>          ..
2020-08-19  11:59 AM    <SYMLINKD>     jdk [jdk1.8]
2020-10-28  12:41 PM    <DIR>          jdk-11.0.9.11-openj9
2020-08-05  12:14 AM    <SYMLINKD>     jdk1.6 [jdk1.6.0_211]
2020-08-05  12:13 AM    <DIR>          jdk1.6.0_211
2020-03-11  01:31 AM    <DIR>          jdk1.8.0_231
2020-10-28  12:40 PM    <DIR>          jdk1.8.0_271
               0 File(s)              0 bytes
               8 Dir(s)  162,629,304,320 bytes free

C:\Tools\Java>mklink /D jdk1.8 jdk1.8.0_231
symbolic link created for jdk1.8 <<===>> jdk1.8.0_231

C:\Tools\Java>java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b32)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b32, mixed mode)

C:\Tools\Java>unlink jdk1.8

C:\Tools\Java>mklink /D jdk1.8 jdk1.8.0_271
symbolic link created for jdk1.8 <<===>> jdk1.8.0_271

C:\Tools\Java>java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b32)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b32, mixed mode)
    
C:\Tools\Java> dir

2020-08-19  11:59 AM    <SYMLINKD>     jdk [jdk1.8]
2020-10-28  12:44 PM    <SYMLINKD>     jdk1.8 [jdk1.8.0_271]
2020-03-11  01:31 AM    <DIR>          jdk1.8.0_231
2020-10-28  12:40 PM    <DIR>          jdk1.8.0_271

In the above example, JAVA_HOME=C:\Tools\Java\jdk and PATH=%JAVA_HOME%\bin;%PATH%. jdk is a sym-link, presently pointing to jdk1.8, which in the above example was reset from pointing to 1.8.0_231 to 1.8.0_271 ( Don't forget to include /D for directory link.

The jenkins.xml can reference the executable by any of:
<executable>java.exe</executable>
<executable>%JAVA_HOME%\bin\java.exe</executable>
<executable>C:\Tools\Java\jdk1.8\bin\java.exe</executable>
or if you want to validate against a specific version:
<executable>C:\Tools\Java\jdk1.8.0_271\bin\java.exe</executable>

answered on Server Fault Oct 24, 2020 by Ian W • edited Oct 29, 2020 by Ian W

User contributions licensed under CC BY-SA 3.0