Automatically set $JAVA_HOME
based on working directory.
Ideally you would use something like maven toolchains or whatever the equivalent is for your build system, but this is not always possible. Eg. the Maven Spotless plugin doesn't support toolchains. Or maybe you're working on a 3p project without toolchain support.
Via fisher (Recommended)
fisher install nakulj/auto-java-home
Copy conf.d/venv.fish
into your conf.d
directory (usually ~/.config/fish/conf.d
)
In the root of any git repo where you want your $JAVA_HOME
set, create a .java_home
file with the location of java you want:
/usr/libexec/java_home -v 1.8 > ~/my_java_8_project/.java_home
/usr/libexec/java_home -v 11 > ~/my_java_11_project/.java_home
You should now see the path update automatically as you move around:
![image](https://private-user-images.githubusercontent.com/3213360/347533210-050657d1-7730-48af-9269-f5ec56196650.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM1NTkwNjgsIm5iZiI6MTcyMzU1ODc2OCwicGF0aCI6Ii8zMjEzMzYwLzM0NzUzMzIxMC0wNTA2NTdkMS03NzMwLTQ4YWYtOTI2OS1mNWVjNTYxOTY2NTAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgxMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MTNUMTQxOTI4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ODY4NmEyNjFkNGI2NWNhYWI5Mjg4NTA5N2M3MDI0NzFkOTAzMDI5ZTY0NGJlMDI0ODk4MmQzNTI4MGM2OTM0ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.OVAqBfIPn2A7NYUqf0Sjl1AyXEfMlVpABZtm4YIhLSM)