Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.