Skip to content
This repository has been archived by the owner on Nov 17, 2022. It is now read-only.

JAVA_HOME variable setup script on linux not compatible with Java-14 #1907

Open
funder7 opened this issue Aug 13, 2020 · 0 comments
Open

JAVA_HOME variable setup script on linux not compatible with Java-14 #1907

funder7 opened this issue Aug 13, 2020 · 0 comments

Comments

@funder7
Copy link

funder7 commented Aug 13, 2020

Please, tell us what's the problem?

[x] Wrong documentation
[x] Improvement of existing article

Please, tell us more details

Currently the docs are telling to set the JAVA_HOME variable this way:

export JAVA_HOME=$(update-alternatives --query javac | sed -n -e 's/Best: *\(.*\)\/bin\/javac/\1/p')

This can work, but not always: in a system where Java 14 is installed, then it will be reported as the "best" option, which in turn will not be compatible with Nativescript as it supports Java >= 8 and <= 13. "Best" is the most recent version .

I've found a good script, which is working fine, it depends on which version the user selects from update-alternatives:

#!/bin/bash
if [ -z "${JAVA_HOME}" ]
then
    JAVA_HOME=$(readlink -nf $(which java) | xargs dirname | xargs dirname | xargs dirname)
    if [ ! -e "$JAVA_HOME" ]
    then
        JAVA_HOME=""
    fi
    export JAVA_HOME=$JAVA_HOME
fi

To switch the default java version to be used:

sudo update-alternatives --config java
sudo update-alternatives --config javac
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant