gantsign / ansible-role-java

Ansible role for installing Java from Adoptium

Home Page:https://galaxy.ansible.com/gantsign/java

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JAVA_PATH

030 opened this issue · comments

jdk 14 has been installed

ls /opt/java/
jdk-11.0.6 jdk-14

However java -version does not return anything. I had to create a symlink in order to make it work. Could you set the java path as well?

Creating a symlink to /usr/local/bin works as well

@030 Thanks for raising this issue, but this role already adds Java to the PATH environment variable (there's even a test to make sure it works). Unfortunately, there are multiple ways of doing this in Linux each with their own advantages and disadvantages.
The technique this role uses is to create a shell script under /etc/profile.d (/etc/profile.d/java.sh); the advantage of this technique is it involves creating a new file (rather than modifying an existing file - which is more error-prone and more likely to cause upgrade issues). The disadvantage is this technique is it only works if you run the profile initialization. Your bash profile typically gets initialized when you run bash --login or source /etc/profile. Most of the time this is done for you, but depending on how you run your shell it may not be.
This role intentionally doesn't create symbolic links under /usr/local/bin because the are multiple executables bundled with the JDK, these vary between JDK version and even distribution, and then there's the risk of JAVA_HOME getting out of sync with the symbolic links.
If you're using Java for development I suggest you use SDKMAN!, it makes installing and switching between Java versions very easy. I have another Ansible role for installing SDKMAN! gantsign.sdkman.