halcyon/asdf-java

Set java home reports file name too long (zsh) and does not set java home

Closed this issue · 2 comments

Description

Using asdf-java, with version adoptopenjdk-8.0.282+8.openj9-0.24.0, in zsh. When I add . ~/.asdf/plugins/java/set-java-home.zsh to ~/.zshrc I get file name too long errors and java_home is not set.

Environment

echo $0 -> zsh
echo $SHELL -> /bin/zsh
asdf --version -> v0.8.0
asdf plugin list --urls --refs -> java https://github.com/halcyon/asdf-java.git master be57a70
cat ~/.asdfrc -> java_macos_integration_enable = yes

Steps taken

  • Install java, adoptopenjdk-8.0.282+8.openj9-0.24.0 in my case: asdf install java adoptopenjdk-8.0.282+8.openj9-0.24.0
  • Open zshrc file: ~/.zhsrc
  • Add . ~/.asdf/plugins/java/set-java-home.zsh as final line
  • Save & close rc file
  • Restart prompt or call . ~/.asdf/plugins/java/set-java-home.zsh

Expected

  • For Java_Home to be set
  • No errors to be logged

Actual

dirname: /Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin
total 7512
drwxr-xr-x  44 bremeeni  staff   1.4K Apr 22  2020 ./
drwxr-xr-x  13 bremeeni  staff   416B Mar 22 13:23 ../
-rwxr-xr-x   1 bremeeni  staff    86K Apr 22  2020 appletviewer
...
-rwxr-xr-x   1 bremeeni  staff    86K Apr 22  2020 xjc
/Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin: File name too long

is output; for each and every statement executed from then onwards.

Temporary fix/workaround

  • Remove line from ~/.zshrc
  • Open a new shell, close the old
  • Set java home manually, e.g. export JAVA_HOME=$(/usr/libexec/java_home)

Am I missing something?

Seeing your output it seems you changed the dirname command to a ls -al command.

What happens if you do:

/usr/bin/dirname /Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin. For me that results in:

❯ /usr/bin/dirname /Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0/bin
/Users/bremeeni/.asdf/installs/java/adoptopenjdk-8.0.282+8.openj9-0.24.0

If this makes the output the same for you, you could replace the 2 dirnames in set-java-home.zsh to /usr/bin/dirname.

Sorry for not replying for so long, I somehow did not get a notification and have solved the issue in the mean time.

In my .zshrc there's function chpwd () { pwd && ls -FGlahp } .
I've solved the issue by using something very similar to what you suggested and the set-java-home in general:

function asdf_update_java_home {
  asdf current java 2>&1 > /dev/null
  if [[ "$?" -eq 0 ]]
  then
      export JAVA_HOME=$(asdf where java)
  fi
}

autoload -U add-zsh-hook
add-zsh-hook precmd asdf_update_java_home