-
Notifications
You must be signed in to change notification settings - Fork 89
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
maven.terminal.useJavaHome doesnt work if JAVA_HOME already set by shell startup scripts #495
Comments
Here is a misunderstanding of setting |
Okay, I am not clear how this works. I am listing the info from my system
Run custom maven goal from explorer
Change this settings
I still get JDK 11 when I run
My intention is to use JDK 8, which is specific to this project and not global JDK 11. |
Sorry about the misleading. If you want to use a specific JAVA_HOME, you can either:
I can reproduce your zsh issue, and it works well for bash as you mentioned. This extension tells vscode to append custom envs(e.g. JAVA_HOME) when opening a new integrated terminal. I just double checked it, the envs are correctly passed to vscode. and I guess that's probably related to how vscode loads the profiles, for zsh particularly. Let me share my findings. I have JDK 11/13/14 installed.
For BashRun
Run custom maven goal from explorer
For ZshNow I set
Run custom maven goal from explorer
Now if I remove JAVA_HOME from
Run custom maven goal from explorer
My guess is, for zsh, vscode first loads the custom envs passed by this extension, and later from |
@jahan01 try printing out the values in
I'm not familiar with zshell, but I think there's no way to interfere zshell's behavior in this extension... |
@Eskibear : yes, you are right in saying that vscode sets the env variable at the terminal creation but it is overridden if the avariables are also set in shell start up scripts( I just observed behaviour is same both in zsh and bash. If you set This also doesnt work (i.e., overridden by shell startup scripts)
Earlier I had not set |
OK, then I think it can be a regression introduced by #240 . Previously it manually executed "export" statements for different kind of shells. So no matter what was written in the startup scripts, the command finally won... Do you think we should revert the change and back to previous behavior? The side effect would be:
also /cc @jdneo |
@Eskibear I am not an expert, but this is exactly what vscode-python extension do to activate virtual environment (though it doesnt do Somehow, intellij idea and pycharm doesnt need to do these hacks, somehow the set correct variables without executing statements after terminal creation. |
BTW, FYI I have opened a ticket in microsoft/vscode#98490 to get |
|
@thakkarparth007 Thank you for reporting this. When did you see this error, and what's the full error message? |
@Eskibear here's the error message I got when I saved a pom.xml file, or on clicking the "Dependencies" option in the maven toolbar.
This is when my settings.json file looked like this:
I'm using Jabba for managing Java environments, and my After seeing the explanation for I've tried to give all details I could think of, let me know if you need more details! |
Thanks, it's very helpful for locating the problem. The problem is, Maven requires you to set JAVA_HOME env (e.g. to run
If |
But I do have JAVA_HOME set in my zsh profile. I run I'll try |
BTW, I just searched vscode's repo for zsh issues, check if microsoft/vscode#143061 helps? |
Trying to make it work on RockyLinux 8.6 I`ve added this piece of config everywhere (User / Workspace / Folder )
And opening a new integrated shell only to find that the FOO env variable isn't present. tried that after banging my head over JAVA_HOME. so the problem isn't linked to having JAVA_HOME set in .bashrc |
I wrote a simple maven plugin to test this problem out, and here's what I found. So, I use WSL2 with Here I set Here, I don't specify |
Looks like JAVA_HOME is not loaded when vscode starts the terminal. Can you run |
On macOS, the following solved the problem. "maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "/xxx/java/21"
},
{
"environmentVariable": "ZDOTDIR",
"value": "~/.zsh_dummy"
},
], |
Another ways to ignore the system's JAVA_HOME env var. macOS
"maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "/xxx/java/21"
},
{
"environmentVariable": "ZDOTDIR",
"value": "/xxx/rcdir"
}
],
if [ -r ~/.zshrc ]; then
JAVA_HOME_BACKUP=$JAVA_HOME
source ~/.zshrc
export JAVA_HOME=$JAVA_HOME_BACKUP
fi
export PATH="$JAVA_HOME/bin:$PATH" Linux
"maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "/xxx/java/21" // For Maven
}
],
"terminal.integrated.profiles.linux": {
"bash": {
"path": "bash",
"env": {"JAVA_HOME": "/xxx/java/17"}, // Terminal Default
"args": ["--rcfile", "/xxx/rcdir/.bashrc"]
},
},
if [ -r ~/.bashrc ]; then
JAVA_HOME_BACKUP=$JAVA_HOME
source ~/.bashrc
export JAVA_HOME=$JAVA_HOME_BACKUP
fi
export PATH="$JAVA_HOME/bin:$PATH" Windows
"maven.terminal.customEnv": [
{
"environmentVariable": "JAVA_HOME",
"value": "C:¥¥xxx¥¥java¥¥21"
}
], |
hi,this is my if [ -z "$JAVA_HOME" ]; then
JAVA_HOME=$(/usr/libexec/java_home)
export JAVA_HOME
echo "JAVA_HOME not set, defaulting to $JAVA_HOME"
else
echo "JAVA_HOME is already set to $JAVA_HOME"
fi
|
Describe the bug
"maven.terminal.useJavaHome": true,
ormaven.terminal.customEnv
doesnt overrideJAVA_HOME
on zsh. It works in bash shell (by changing"terminal.integrated.shell.osx": "/bin/bash"
).Due to this I am not able to compile/package my project by clicking in mvn explorer as by default it uses my system jdk, not my project jdk as specified in
java.home
To Reproduce
Steps to reproduce the behavior:
-version
Java version:
in the console is same asjava.home
in your settings, not theJAVA_HOME
set by your.zshrc
or.zshenv
maven.terminal.customEnv
is able to set variables other thenJAVA_HOME
. i.e,MY_MVN_ENV
is set properly in the terminalExpected behavior
System wide
JAVA_HOME
is overridden withjava.home
and able to compile using project specific JDK version.Environments (please complete the following information as much as possible):
The text was updated successfully, but these errors were encountered: