IntelliJ IDEA terminal java version issue
Asked Answered
C

4

6

I am facing some issue in IntelliJ IDEA compiler settings. I have JDK 8 installed and one of the project in idea works only on JDK 6.

I have changed the compiler version in idea in preferences -> Java Compiler page and restarted idea.

Javac in Preferences

The problem I am facing is that on idea Terminal the version is not getting updated. Is there any way other than setting the JAVA_HOME in .profile within idea to solve this?

java version

Catenane answered 5/8, 2015 at 12:49 Comment(0)
V
2

I would say it works as expected. You have changed the compiler version for IntelliJ IDEA only, thus it affects the compilation process in IntelliJ IDEA. This setting does not (and should not) affect your terminal session environment. You can change the shell launch arguments in File -> Settings -> Tools -> Terminal -> Shell path. Since this setting can be set per a project (but not per a module, as far as I understand), you can specify project-specific settings there. I'm not sure if it's possible to pass some project-specific variables there and you probably have to hard-code arguments, but in simple case it can be changed like, let's say, cmd.exe /k echo WELCOME (on my Windows machine) or something similar for bash.

Vallo answered 5/8, 2015 at 13:25 Comment(2)
Thanks, can i update the shell path settings to point to JSK 1.6?Catenane
I got it working, I used following command in Settings -> Tools -> Terminal -> Shell path "zsh && export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.6/Contents/Home"Catenane
C
11

Yes, you can set this in Preferences > Tools > Terminal > Environment Variables. Setting JAVA_HOME in Terminal Preferences

This setting is for the current project. So you can set a different value for each project.

The one caveat is you have to remember to update this whenever you modify your project's JDK (particularly major version upgrades).

The setting will take place when you next open a new terminal (or restart the IDE).

Cornelius answered 23/10, 2019 at 20:25 Comment(2)
2023 this is not working anymoreCasavant
@Casavant it works for my Windows 10+PowerShell setupCallup
C
2

In short: you're looking at two different things.

The terminal in IntelliJ is in fact an operating system terminal; it will look for the java executable in your "path" (denoted by %PATH% on Windows, or $PATH on *nix).

The setting shown in your screenshot, on the other hand, describes what kind of compiled bytecode should be generated for your project. The Java compiler can generate bytecode for earlier versions of the Java VM. In this case, you're asking the Java compiler used by IntelliJ to generate code that can be ran on a Java 6 VM, regardless of which version of Java is used to run IntelliJ itself.

Crawly answered 5/8, 2015 at 12:58 Comment(1)
No even for the java -version i see the same version 1.8Catenane
V
2

I would say it works as expected. You have changed the compiler version for IntelliJ IDEA only, thus it affects the compilation process in IntelliJ IDEA. This setting does not (and should not) affect your terminal session environment. You can change the shell launch arguments in File -> Settings -> Tools -> Terminal -> Shell path. Since this setting can be set per a project (but not per a module, as far as I understand), you can specify project-specific settings there. I'm not sure if it's possible to pass some project-specific variables there and you probably have to hard-code arguments, but in simple case it can be changed like, let's say, cmd.exe /k echo WELCOME (on my Windows machine) or something similar for bash.

Vallo answered 5/8, 2015 at 13:25 Comment(2)
Thanks, can i update the shell path settings to point to JSK 1.6?Catenane
I got it working, I used following command in Settings -> Tools -> Terminal -> Shell path "zsh && export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.6/Contents/Home"Catenane
O
0

The compiler version inside your IDE has nothing to do with the compiler version used by your terminal.

I would suggest creating a function in your .bashrc to allow switching between jdk6 and jdk8 simply by exporting the relevant paths.

Then when needed you can simply call the function from your terminal (either inside an IDE or not) and switch to the corresponding jdk.

Operator answered 5/8, 2015 at 12:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.