Can I start OH 3.1 in a different Java environment?

Hi Community. Thank you for the work you are doing with OH 3, it’s a hobby for me at the moment while I figure out what I can do with it. Plenty of inspired posts to keep me going but for now I have a Java questions please.

TIA for reading and devoting mind-time to this.

Context
I’m using a relatively recent desktop computer, plenty of RAM and HDD space, running Ubuntu 20.04 LTS headless server with:

  • OpenHab 3.1
  • SubSonic
  • Nextcloud
  • Homebridge
  • Wordpress
  • Apache2
  • MariaDB

I have some mid-level skills in this space, so am able to understand complex concepts but my search skills are frustrating me, so I thought I would ask to see if anyone else has the experience to help me a little faster than me trying to help myself.

The Ask
May I ask if it’s possible to start up OH 3.1 in a separate Java environment. I have Zulu 8, 11 and openJDK 8 and 11 on the dekstop. Default is current Zulu 8 because Subsonic is used heavily by the family and is incompatible with 11. Funny thing, OH3.1 is incompatible with 8.

So, easiest thing I could think of was use 8 and see if I can run OH3.1 by specifying a different Java environment specifically for it.

I came across this post: How to point OH2 to a different java version and while that is specific to rPI installs, does anyone have experience with OH3 in Ubuntu to start in a different Java environment to the default as chosen through ’ sudo update-alternatives --config java ’ (which will break my SubSonic install).

Yes, yes I know the obvious answer may be “jeez just use a few Raspbery Pi’s and all the problems will go away” but I really just want one Platform

I have sort of the same issue, running a unifi controller (which requires java 8) on the same computer as openhab. Adding

JAVA_HOME="/usr/lib/jvm/zulu11-ca-amd64/"

To /etc/default/openhab makes OH use java 11 instead. (Of course you might need to adapt the path to your setup).

2 Likes

Mate, Anders, if you’re ever traveling near Canberra let me know and I’ll shout you a beer (or coffee).

Worked like a charm, thank you.

Mine was JAVA_HOME="/usr/lib/jvm/zulu-11-amd64/"

Not really Java 8 & 11 are both LTS versions but Java 8 is nearing its end of support for patches, etc. OH3 will NOT run in Java 8. Perhaps you could use a container system such as Docker to run OH in a container. I have successfully run OH 2 & 3 in containers on the same system.

That’s fair enough - Docker is a little foreign to me so far. I’m used to being able to have full control over (for example) the ports I run things on. This desktop being a ‘jack of all trades’ I’m trying to keep it under as much control as I can.

However, not to fear - the solution for me was to edit the configuration file for OH and specify the java home directory - works like a charm now :slight_smile:

1 Like

Is there any identical way for a windows enviroment? any hints for me?
THX

Windows as well uses JAVA_HOME to identify the java installation to be used.

Yes, i know.
But because of other application JAVA_HOME is alreday set to another java installtion.

Also tried now to work with the wrapper and absolut path to zulu 11, but also got errors about the Equinox container

#*******************************************************
# openHAB-wrapper.conf for Windows Service Installation
#*******************************************************

# openHAB installation dir (Adapt this first setting to your system)
set.default.OPENHAB_HOME=C:\Openhab3

# Wrapper Properties
set.default.OPENHAB_CONF=%OPENHAB_HOME%\conf
set.default.OPENHAB_RUNTIME=%OPENHAB_HOME%\runtime
set.default.OPENHAB_USERDATA=%OPENHAB_HOME%\userdata
set.default.OPENHAB_LOGDIR=%OPENHAB_USERDATA%\logs
set.default.KARAF_HOME=%OPENHAB_RUNTIME%
set.default.KARAF_BASE=%OPENHAB_USERDATA%
set.default.KARAF_DATA=%OPENHAB_USERDATA%
set.default.KARAF_ETC=%OPENHAB_USERDATA%\etc
set.default.PATH=%PATH%;%KARAF_BASE%\lib;%KARAF_HOME%\lib

# Java Application
wrapper.working.dir=%KARAF_BASE%
wrapper.java.command=C:\Program Files\Zulu\zulu-11\bin\java
wrapper.java.mainclass=org.apache.karaf.wrapper.internal.service.Main
wrapper.java.classpath.1=%KARAF_HOME%\lib\boot\*.jar
wrapper.java.classpath.2=%KARAF_DATA%\lib\wrapper\*.jar
wrapper.java.classpath.3=%KARAF_HOME%\lib\jdk9plus\*.jar
wrapper.java.classpath.4=%KARAF_HOME%\lib\endorsed\*.jar
wrapper.java.library.path.1=%KARAF_DATA%\lib\wrapper\

# Java Parameters
wrapper.java.additional.1=-Dkaraf.home="%KARAF_HOME%"
wrapper.java.additional.2=-Dkaraf.base="%KARAF_BASE%"
wrapper.java.additional.3=-Dkaraf.data="%KARAF_DATA%"
wrapper.java.additional.4=-Dkaraf.etc="%KARAF_ETC%"
wrapper.java.additional.5=-Dcom.sun.management.jmxremote
wrapper.java.additional.6=-Dkaraf.startLocalConsole=false
wrapper.java.additional.7=-Dkaraf.startRemoteShell=true
wrapper.java.additional.8=-Dopenhab.home="%OPENHAB_HOME%"
wrapper.java.additional.9=-Dopenhab.conf="%OPENHAB_HOME%\conf"
wrapper.java.additional.10=-Dopenhab.runtime="%OPENHAB_HOME%\runtime"
wrapper.java.additional.11=-Dopenhab.userdata="%OPENHAB_HOME%\userdata"
wrapper.java.additional.12=-Dopenhab.logdir="%OPENHAB_USERDATA%\logs"
wrapper.java.additional.13=-Dfelix.cm.dir="%OPENHAB_HOME%\userdata\config"
wrapper.java.additional.14=-Dorg.osgi.service.http.port=7777
wrapper.java.additional.15=-Dorg.osgi.service.http.port.secure=7779
wrapper.java.additional.16=-Djava.util.logging.config.file="%KARAF_ETC%\java.util.logging.properties"
wrapper.java.additional.17=-Dkaraf.logs="%OPENHAB_LOGDIR%"
wrapper.java.additional.18=-Dfile.encoding=UTF-8
wrapper.java.maxmemory=512

# Wrapper Logging Properties
wrapper.console.format=PM
wrapper.console.loglevel=INFO
wrapper.logfile=%OPENHAB_USERDATA%\logs\wrapper.log
wrapper.logfile.format=LPTM
wrapper.logfile.loglevel=INFO
wrapper.logfile.maxsize=10m
wrapper.logfile.maxfiles=5
wrapper.syslog.loglevel=NONE

# Wrapper Windows Properties
wrapper.console.title=openHAB
wrapper.ntservice.name=openHAB
wrapper.ntservice.displayname=openHAB
wrapper.ntservice.description=openHAB Service
wrapper.ntservice.dependency.1=
wrapper.ntservice.starttype=AUTO_START
wrapper.ntservice.interactive=false

All other error messages that i found in relation to Equinox container are related to using the wrong Java version.
According to my limited understanding it is essential to have JAVA_HOME set to the correct value.
As you mentioned you need to use JAVA_HOME set to an other version. I would assume that this is the problem.
Can’t you set JAVA_HOME for just that one user in the users environment settings overruling the system wide set JAVA_HOME envorinment variable ? For a test you may set that environment variable just before starting up OH from within a cmd box.

I found my problem…
The given absoult path to Zulu11 was not right…

So finally it works without handling JAVA_HOME for OH3 by starting OH3 as a service with the absolut path to ZULU11 inside the wrapper config.

THX