Page 1 of 1

HOWTO: set proper Java in Ubuntu Bionic 18.04 LTS

PostPosted: Fri Apr 27, 2018 8:14 am
by skiaccianos
Hi all,
Ubuntu Bionic has been released yesterday and ships a new default java (openjdk-11-jre/bionic,now 10.0.1+10-3ubuntu1): Serviio is not working with this release, so you have to install jre 8 alongside the 11 and make it the default. Like this:

  Code:
matteo@TMP258-MG:~$ sudo apt list --installed |grep jre                                                                                                                                       
                                                                                                                                                                                               
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.                                                                                                                 
                                                                                                                                                                                               
default-jre/bionic,now 2:1.10-63ubuntu1~02 amd64 [installato, automatico]
default-jre-headless/bionic,now 2:1.10-63ubuntu1~02 amd64 [installato, automatico]
openjdk-11-jre/bionic,now 10.0.1+10-3ubuntu1 amd64 [installato, automatico]
openjdk-11-jre-headless/bionic,now 10.0.1+10-3ubuntu1 amd64 [installato, automatico]
openjdk-8-jre/bionic,now 8u162-b12-1 amd64 [installato]                                              <<<<< apt get install this one
openjdk-8-jre-headless/bionic,now 8u162-b12-1 amd64 [installato, automatico]
matteo@TMP258-MG:~$ sudo update-alternatives --config java
Sono disponibili 2 scelte per l'alternativa java (che fornisce /usr/bin/java).

  Selezione    Percorso                                        Priorità  Stato
------------------------------------------------------------
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      modalità automatica
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      modalità manuale
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      modalità manuale

Press <enter> to keep the current choice[*], or type selection number: 2
matteo@TMP258-MG:~$


Regards

Re: HOWTO: set proper Java in Ubuntu Bionic 18.04 LTS

PostPosted: Fri Apr 27, 2018 8:53 am
by zip
how does it fail with Java 11?

There is support for Java 9 in serviio.sh

  Code:
# Check if we are using Java9
JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}')
case "$JAVA_VERSION" in
    \9*) JAVA9_OPTS="--add-modules java.xml.ws,jdk.unsupported" ;;
    *) JAVA9_OPTS="" ;;
esac


I assume it'd have to be updated for Java 10/11 and use the same behaviour as for Java 9 (ie add the --add-module opts)

Re: HOWTO: set proper Java in Ubuntu Bionic 18.04 LTS

PostPosted: Fri Apr 27, 2018 10:14 pm
by skiaccianos
Hi zip,
this is how it fails

  Code:
matteo@TMP258-MG:~$ sudo update-alternatives --config java
Sono disponibili 2 scelte per l'alternativa java (che fornisce /usr/bin/java).                                                                                                                 
                                                                                                                                                                                               
  Selezione    Percorso                                        Priorità  Stato                                                                                                                 
------------------------------------------------------------                                                                                                                                   
  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      modalità automatica                                                                                                   
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      modalità manuale                                                                                                     
* 2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      modalità manuale                                                                                                     
                                                                                                                                                                                               
Press <enter> to keep the current choice[*], or type selection number: 0                                                                                                                       
update-alternatives: viene usato /usr/lib/jvm/java-11-openjdk-amd64/bin/java per fornire /usr/bin/java (java) in modalità automatica                                                           
matteo@TMP258-MG:~$                                                                                                                                                                             
matteo@TMP258-MG:~$                                                                                                                                                                             
matteo@TMP258-MG:~$ iio                                                                                                                                                                         
[1] 9097                                                                                                                                                                                       
matteo@TMP258-MG:~$                                                                                                                                                                             
matteo@TMP258-MG:~$
matteo@TMP258-MG:~$
matteo@TMP258-MG:~$
[1]+  Completato              /home/matteo/.serviio/bin/serviio.sh
matteo@TMP258-MG:~$
matteo@TMP258-MG:~$

Re: HOWTO: set proper Java in Ubuntu Bionic 18.04 LTS (updat

PostPosted: Sat Apr 28, 2018 8:08 am
by bolzass
Hi skiaccianos!,
Nothing to see here....

But to fix what zip is talking about, you should add versions to case... Several ways:
Add lines with versions, or just merge it in the case:
  Code:
# Check if we are using Java9, or 10...
JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}')
case "$JAVA_VERSION" in
    9*|10*) JAVA9_OPTS="--add-modules java.xml.ws,jdk.unsupported" ;;
    *) JAVA9_OPTS="" ;;
esac


Or change the case with only to check if greater or equal than 9:
  Code:
# Check if we are using Java9 or greater...
JAVA_VERSION=$("$JAVA" -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;')
[ "$JAVA_VERSION" -gt 18 ] && JAVA9_OPTS="--add-modules java.xml.ws,jdk.unsupported" || JAVA9_OPTS=""


I changed it for you by the 2nd options in serviio.sh


[EDITED]. Corrected case words and updated serviio.sh (Thanks zip)
.

Re: HOWTO: set proper Java in Ubuntu Bionic 18.04 LTS

PostPosted: Sat Apr 28, 2018 12:31 pm
by zip
[quote="bolzass"
But to fix what zip is talking about, you should add versions to case... [/quote]
Are you sure your case works?

Java 8's -version results in something like 1.8.0-xxx
Java 9's -version results in something like 9 (not 1.9)

But maybe I'm just not reading the sed line correctly

Re: HOWTO: set proper Java in Ubuntu Bionic 18.04 LTS

PostPosted: Sat Apr 28, 2018 1:59 pm
by bolzass
zip wrote:Are you sure your case works?

Java 8's -version results in something like 1.8.0-xxx
Java 9's -version results in something like 9 (not 1.9)

You are right!, didn't noticed about it :oops:. It should be:
  Code:
# Check if we are using Java9, or 10...
JAVA_VERSION=$("$JAVA" -version 2>&1 | awk -F '"' '/version/ {print $2}')
case "$JAVA_VERSION" in
    9*|10*) JAVA9_OPTS="--add-modules java.xml.ws,jdk.unsupported" ;;
    *) JAVA9_OPTS="" ;;
esac


zip wrote:But maybe I'm just not reading the sed line correctly

You read it fine, in that case would work also as would result in 9x and 10x (90 & 100 for the last ones) for versions >=9, that are greater than 18 and would take into account new java numbering in the future updates (18.9, etc.) :mrgreen: [this is which I prefer]. Ops :oops: , also mistaken (put 19 not 18..):
  Code:
# Check if we are using Java9 or greater...
JAVA_VERSION=$("$JAVA" -version 2>&1 | sed -n ';s/.* version "\(.*\)\.\(.*\)\..*".*/\1\2/p;')
[ "$JAVA_VERSION" -gt 18 ] && JAVA9_OPTS="--add-modules java.xml.ws,jdk.unsupported" || JAVA9_OPTS=""



Will correct original post!!!!. Thanks zip!

.