user4948585
user4948585

Reputation:

IntelliJ IDEA terminal java version issue

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

Upvotes: 6

Views: 31366

Answers (4)

David Siegal
David Siegal

Reputation: 4578

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

Upvotes: 11

Lyubomyr Shaydariv
Lyubomyr Shaydariv

Reputation: 21125

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.

Upvotes: 2

George Karanikas
George Karanikas

Reputation: 1244

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.

Upvotes: 0

mthmulders
mthmulders

Reputation: 9705

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.

Upvotes: 2

Related Questions