Comments (17)
Zsh users can add this to .zshrc
:
# set JAVA_HOME on every change directory
function asdf_update_java_home {
asdf current java 2>&1 > /dev/null
if [[ "$?" -eq 0 ]]
then
export JAVA_HOME=$(asdf where java)
fi
}
precmd() { asdf_update_java_home; }
# end set JAVA_HOME
Also, suggest to add it to the README.
from asdf-java.
I live with this in my .bashrc
as a workaround. It updates JAVA_HOME
every time it updates the prompt:
function asdf_update_java_home {
asdf current java 2>&1 > /dev/null
if [[ "$?" -eq 0 ]]
then
export JAVA_HOME=$(asdf where java)
fi
}
function prompt_command {
__vte_prompt_command # put here whatever previous PROMPT_COMMAND value
asdf_update_java_home
}
export PROMPT_COMMAND=prompt_command
Maybe you could add this to the README while the hook is not there.
from asdf-java.
@rubencaro @donbeave @joschi @jonatan-ivanov - how would you feel about #76 ?
from asdf-java.
@jonatan-ivanov I think there's currently no hook in asdf which will invoke a plugin when a version was selected (asdf global <plugin> <version>
or asdf local <plugin> <version>
).
from asdf-java.
@jonatan-ivanov exec-env
controls the environment when a shim is executed (for example $HOME/.asdf/shims/java
) but it doesn't change the environment you're calling asdf or the shim from, which would be required to update $JAVA_HOME
after changing the version with asdf shell
, asdf local
, or asdf global
.
It's not that it couldn't be added to asdf, but this hook doesn't exist right now, so there's nothing asdf-java could do about it. It has to be added in asdf first.
Related issue: asdf-vm/asdf#384
from asdf-java.
@joschi is this something the asdf-direnv
plugin can solve? Does it have hooks for this kind of functionality?
from asdf-java.
@rubencaro You're right. I mixed up precmd
and preexec
. 👍
For reference: https://github.com/rothgar/mastering-zsh/blob/master/docs/config/hooks.md#hooks
from asdf-java.
@halcyon How about my solution? It worked with both system
java and asdf
provider java
asdf_update_java_home() {
# shellcheck disable=SC2046
JAVA_HOME=$(realpath $(dirname $(readlink -f $(asdf which java)))/../)
export JAVA_HOME
}
autoload -U add-zsh-hook
add-zsh-hook precmd asdf_update_java_home
https://github.com/thuandt/zsh-config/blob/master/functions.sh#L3-L7
https://github.com/thuandt/zsh-config/blob/master/my-zsh-config.plugin.zsh#L103
from asdf-java.
@halcyon LGTM, I just tested zsh
script, works perfectly.
from asdf-java.
You'll need to restart your shell for JAVA_HOME to be updated.
from asdf-java.
@halcyon Yes, that is the issue, I should not, right? :)
from asdf-java.
@joschi I'm not very familiar with asdf but isn't exec-env
for this? https://asdf-vm.com/#/plugins-create?id=binexec-env
The main documentation is not very verbose, this might help a little more: https://github.com/asdf-vm/asdf/blob/master/docs/core-manage-versions.md#shims
And here how it's used: https://github.com/asdf-vm/asdf/blob/master/lib/utils.bash#L527-L543
from asdf-java.
@joschi Thank you very much!
from asdf-java.
@halcyon do you prefer a PR adding those to the readme? I could do it.
from asdf-java.
@rubencaro @donbeave Be aware that it can substantially slow down your shell when asdf
is being called before every single command you're running in your shell.
from asdf-java.
@rubencaro @donbeave Be aware that it can substantially slow down your shell when
asdf
is being called before every single command you're running in your shell.
I didn't notice any effect after months using it like that. You should take into account that this will call asdf
only when the shell renders the prompt, so right before going idle. It will not slow down execution of every single command 😁.
Maybe it would be enough to add a warning for that specific usecase (i.e. if somebody needs to render the prompt many times per second ?).
from asdf-java.
Thank you @thuandt
I've integrated your solution into PR #76
from asdf-java.
Related Issues (20)
- Incorrect Checksum for `microsoft-11.0.16.1`
- Can't use Java temurin-17.0.5+8 HOT 1
- set-java-home.zsh is painfully slow; can we make it only run on startup and when the user changes their directory? HOT 6
- Can't Pull Temurin jdk-11.0.17+8 HOT 1
- jdk-linux-aarch64.tsv misses some zulu versions
- Major version should be enough in .tool-versions HOT 2
- Not finding java jdk 8 in version list HOT 1
- Support install from cache
- java_release_type property not working, EA releases not found HOT 4
- Support for nushell
- Unable to open JAR files with Linux (Manjaro and Ubuntu)
- `asdf list all java 11` does not work HOT 3
- Use user home for MacOS `/usr/libexec/java_home` integration HOT 1
- No Oracle JDK 21 in the list HOT 1
- temurin/adoptopenjdk JDK 21 not appearing in the list of `ga` releases HOT 1
- Install of java versions fail when in a terminal with output colors for `ls` commands
- Install oracle jdk 8
- Support for CRaC's JDK Build
- Oracle JDK 22 / GraalVM 22 aren't available to download HOT 2
- Only Azul and no JDK options available?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from asdf-java.