Run UniFi Controller As a Service on AdoptOpenJDK

Oracle Java is no longer free for commercial use so I needed to change the Java version on Windows 2008R2 machine to AdoptOpenJDK (as suggested in this article). Took a lot of fumbling around to get it to work. I later confirmed the problem and this workaround on a Server 2016 install.

These instructions assume you are running the UniFi controller as a service. More on that here.

1. Open your UniFi controller and make a backup of your current configuration. Shouldn’t need it but you never know.

2. While Oracle Java is still installed, stop and uninstall the UniFi service:

cd "%UserProfile%\Ubiquiti UniFi\"
java -jar lib\ace.jar stopsvc
java -jar lib\ace.jar uninstallsvc

3. Uninstall Oracle Java from Add or remove programs.

4. Download and install the 64-bit version of AdoptOpenJDK 8 LTS with HotSpot. You only need the runtime environment (JRE) not the development kit (JDK). You should be able to get that here:  https://adoptopenjdk.net/releases.html#x64_win. I actually installed it using Ninite which already I use for general program maintenance. I’m using the default installation directory, C:\Program Files\AdoptOpenJDK\jdk8u202-b08-jre. After the install, from a command prompt, run path and you should see that at the beginning of the path.

5. Install the UniFi service:

cd "%UserProfile%\Ubiquiti UniFi\"
java -jar lib\ace.jar installsvc

Note I found that I could not do a java -jar lib\ace.jar (to list parameters) until I had installed the service. I kept getting the message “Could not find or load main class ?jar”.

UniFi AdoptOpenJDK 1

6. At this point, the service will fail to start:

UniFi AdoptOpenJDK 3

The most recent commons-daemon log (in %UserProfile%\Ubiquiti UniFi\logs) will show “Failed creating java. ServiceStart returned 1”. It’s odd, because java -jar lib\ace.jar info was showing the correct Java.home path:

UniFi AdoptOpenJDK 2

With kudos to this post, a workaround is to modify the service executable in the registry to include the –JavaHome and –Jvm parameters. In regedit, navigate to HKLM\SYSTEM\CurrentControlSet\services\UniFi. You should see that ImagePath contains

"C:\Users\<UserName>\Ubiquiti UniFi\bin\UniFi" //RS//UniFi

Change ImagePath to append the –JavaHome and –Jvm parameters:

"C:\Users\<UserName>\Ubiquiti UniFi\bin\UniFi" //RS//UniFi --JavaHome "C:\Program Files\AdoptOpenJDK\jdk8u202-b08-jre" --Jvm "C:\Program Files\AdoptOpenJDK\jdk8u202-b08-jre\bin\server\jvm.dll"

After that, the service should start.

Update May 25, 2019

The above allows running the current controller on AdoptOpenJDK. However, installing an controller update will fail because the UniFi installer is still looking for Oracle Java.

With thanks to this post and this answer, I confirmed that you can add some dummy registry entries to make the UniFi installer think you have Oracle Java installed. I followed the example of pointing the dummy entries to the actual AdoptOpenJDK installation. Here are the contents of my “Fake Oracle Java entries.reg” file:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment]
"CurrentVersion"="1.8"

[HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\1.8]
"JavaHome"="C:\\Program Files\\AdoptOpenJDK\\jdk8u202-b08-jre"
"RuntimeLib"="C:\\Program Files\\AdoptOpenJDK\\jdk8u202-b08-jre\\bin\\server\\jvm.dll"

Load that into your registry (update if you have a different version) and the UniFi controller installer should run.

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.

This site uses Akismet to reduce spam. Learn how your comment data is processed.