Score:0

How do I run mutiple Java applications with different versions?

in flag

I am using Ubuntu 18.04 LTS and I have 2 apps which need to run with different Java versions. My 1st app (Mirth Connect) needs to run on jre1.8.0_171 and my second app (Power Assist) needs to run on java-11-openjdk-amd64.

$ sudo update-alternatives --config java

There are 3 choices for the alternative java (providing /usr/bin/java).
  
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java   
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java   
2 /usr/lib/jvm/jdk-16.0.2/bin/java              
3 /usr/local/java/jre1.8.0_171/bin/java        

How do I make my 1st app to work with 3 and my 2nd app to work with 1?

$ sudo gedit /etc/profile

if [ "${PS1-}" ]; then
  if [ "${BASH-}" ] && [ "$BASH" != "/bin/sh" ]; then
    # The file bash.bashrc already sets the default PS1.
    # PS1='\h:\w\$ '
    if [ -f /etc/bash.bashrc ]; then
      . /etc/bash.bashrc
    fi
  else
    if [ "`id -u`" -eq 0 ]; then
      PS1='# '
    else
      PS1='$ '
    fi
  fi
fi

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi

JAVA_HOME=/usr/local/java/jre1.8.0_171
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
Score:1
cn flag

Your best bet would probably be to launch these applications from scripts, where you first change some of the environment variables.

export PATH=/usr/lib/jvm/java-11-openjdk-amd64/bin:$PATH
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64

The first change causes the java executable at /usr/lib/jvm/java-11-openjdk-amd64/bin/ to be the one that is found when you launch java. The second change updates the JAVA_HOME environmental variable.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.