简体   繁体   中英

IntelliJ IDEA uses wrong $JAVA_HOME when running things inside it, and I can't change it

I'm on Debian Sid.

In all places imaginable I've set the JDK to 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

Project SDK设置为Java 1.8.0_51(Oracle)

In "Switch IDE boot JDK..." IDE action:

引导SDK设置为Java 1.8.0_51(Oracle)

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.


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:

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"); ).

This happens no matter project I open in the IDE.

In what place else can $JAVA_HOME be accidentally set to the wrong value, /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 . I have no idea why IDEA (heh) apparently ran that script. 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.

I had the same problem. Solution - just close the IntelliJ and then start it again :) But it's not the same as File -> Restart. It has to be a fresh start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM