Linux – What are best practices regarding multiple JVMs on a server

javalinux

Many third party products require a specific version of the JRE or JDK and many of our servers have multiple duties. Application teams argue they should not care where Java is installed. Most of the applications simply rely on environment variables (or whatever Java happens to be lying around) but those teams needing specific versions need to be told where to find their particular version. I don't like the fact that I can now not relocate a JVM without visiting all of the applications that may use it. The obvious answer is to create a program that hides the details from them and expose the location through an API. This solution would require every Java application be wrapped up in some script inquiring about the environment.

I don't like unnecessary complexity or reinventing the wheel. Is there some standard practice, feature built into Java, or obvious solution I am missing?

One I have thought of is for each application to manage a link in its path to point to the Java it wants but I would still need to tell them where it is.

Best Answer

Ideally you need to set two environment variables:

export JAVA_HOME=/java/location
export PATH=$JAVA_HOME/bin:$PATH

You can either create different scripts to start the various programs and set these variables differently in each case. Or you can configure each application to start under a different user account and set these variables in the users appropriate startup script.

$JAVA_HOME/bin needs to come first on the PATH to avoid any other java binaries on the default path being run instead.

Related Topic