[英]IntelliJ IDEA uses wrong $JAVA_HOME when running things inside it, and I can't change it
I'm on Debian Sid. 我在Debian Sid上。
In all places imaginable I've set the JDK to Oracle JDK8: 在所有可以想象的地方,我都将JDK设置为Oracle JDK8:
user@host:~$ cat .bash_profile | grep JAVA_HOME
user@host:~$ cat .bashrc | grep JAVA_HOME
export JAVA_HOME='/usr/lib/jvm/jdk-8-oracle-x64'
user@host:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 auto mode
1 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1069 manual mode
2 /usr/lib/jvm/jdk-7-oracle-x64/jre/bin/java 317 manual mode
* 3 /usr/lib/jvm/jdk-8-oracle-x64/jre/bin/java 318 manual mode
Press <enter> to keep the current choice[*], or type selection number: 3
In "Switch IDE boot JDK..." IDE action: 在“ Switch IDE boot JDK ...” IDE操作中:
In "About" menu item: 在“关于”菜单项中:
If I run xterm
with echo $JAVA_HOME
, it indeed prints /usr/lib/jvm/jdk-8-oracle-x64
, all is fine here. 如果我用
echo $JAVA_HOME
运行xterm
,它的确会打印/usr/lib/jvm/jdk-8-oracle-x64
,在这里一切都很好。
Howerver, if I run echo $JAVA_HOME
in the built-in terminal in IntelliJ IDEA, I can see that $JAVA_HOME
is set to a wrong value: 但是,如果我在IntelliJ IDEA的内置终端中运行
echo $JAVA_HOME
,则可以看到$JAVA_HOME
设置为错误的值:
user@host:~$ echo $JAVA_HOME
/usr/lib/jvm/java-1.7.0-openjdk-amd64
user@host:~$
If I run Java tests or run Maven via IDE plugin, then $JAVA_HOME
is too set to that same incorrect value (this can be demonstrated by Maven or the test runner running a test with something like Runtime.getRuntime().exec("printenv | grep JAVA_HOME");
). 如果我运行Java测试或通过IDE插件运行Maven,则
$JAVA_HOME
也会设置为相同的错误值(这可以由Maven或测试运行程序使用Runtime.getRuntime().exec("printenv | grep JAVA_HOME");
)。
This happens no matter project I open in the IDE. 无论我在IDE中打开任何项目,都会发生这种情况。
In what place else can $JAVA_HOME
be accidentally set to the wrong value, /usr/lib/jvm/java-1.7.0-openjdk-amd64
? $JAVA_HOME
可以在其他什么地方意外地设置为错误的值/usr/lib/jvm/java-1.7.0-openjdk-amd64
吗?
Found it. 找到了。
Did a 做了一个
find / -type f -size -409600c -print0 | xargs -I{} -0 grep -sl "java-1.7.0-openjdk" {}
The guilty file was /etc/profile.d/bigtop.sh
. 有罪的文件是
/etc/profile.d/bigtop.sh
。 I have no idea why IDEA (heh) apparently ran that script. 我不知道为什么IDEA(heh)显然运行了该脚本。 It had the following content:
它具有以下内容:
export MAVEN_HOME=/usr/local/maven
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
export ANT_HOME=/usr/local/ant
export GRADLE_HOME=/usr/local/gradle
export PATH=$MAVEN_HOME/bin:$ANT_HOME/bin:$FORREST_HOME/bin:$GRADLE_HOME/bin:$PATH
export GRADLE_OPTS="-Dorg.gradle.daemon=true"
I changed JAVA_HOME
there, and it fixed my issue. 我在那里更改了
JAVA_HOME
,它解决了我的问题。
I had the same problem. 我有同样的问题。 Solution - just close the IntelliJ and then start it again :) But it's not the same as File -> Restart.
解决方案-只需关闭IntelliJ,然后再次启动它即可:)但这与File-> Restart不同。 It has to be a fresh start.
它必须是一个新的开始。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.