How do I change the JVM used to run IntelliJ on Windows - intellij-idea

I have two Java JDKs installed on my workstation, with jdk1.6.0_41 in my path, and jdk1.7.0_21 available as well, but not in the path.
How can I configure IntelliJ IDEA 13 to use a particular JVM? To be clear, I want to set the JVM used to run IntelliJ itself, not the SDK used for running my code. I am running Windows 7 Enterprise Edition and launch IntelliJ 13.0.2 by running idea64.exe
I have set JAVA_HOME to point to jdk1.7.0_21 but according to the About box it is using jdk1.6.0_41.
This FAQ on the JetBrains web site describes how to do this for Mac, but not for Windows.
This answer suggests using the IDEA_JVM environment variable for Ubuntu 12, but I have tried that and it isn't working.

I suspect you have another setting that is overriding your JAVA_HOME
From Jetbrains docs:
idea64.exe uses this JDK search sequence:
IDEA_JDK_64 environment variable
..\jre64 directory
system Registry
JDK_HOME environment variable
JAVA_HOME environment variable

With newer versions the environment variables are ignored. Instead there is a new action "Choose Boot Java Runtime". The easiest way to get to it is via "Find Action" Ctrl+Shift+A.
You can also edit the setting via the .jdk file in your user configuration directory, e.g. %APPDATA%\JetBrains\IntelliJIdea2021.3\idea64.exe.jdk. This is a plain text file containing only the path to the JDK.
It is not recommended to do this, and you should use the JDK that is bundled with IDEA.

CTRL+ALT+SHIFT+S to go to Project Structure
Under Platform Settings, go to SDKs.
Use the + green icon to add a new SDK and set it to that one.

Related

How to define IDEA JDKs from environment variables?

We have a preexisting developer kit which contains a variety of different JDKs we need because of reasons. This kit defines environment variables such as JDK_7 and JDK_8 pointing to the appropriate directories. These paths are stable inside the kit but are not stable between developer's and build automation machines. The build scripts we use for build automation rely on these variables to set the appropriate JDK in each case. Gradle recently introduced support for detecting toolchains from environment variables, which we are using with great success.
We are now evaluating using IntelliJ IDEA as an IDE for our projects, motivated by its great Gradle support. How can we configure IDEA with JDKs from environment variables?
It is acceptable for us to create a custom plugin to adapt IDEA to our developer kits. What extensions points can we use to inject JDKs into IDEA's platform or project settings?
IDE resolves the JVM for Gradle using below algorithm:
Checks the gradle.properties file for the appropriate Gradle JVM specified in org.gradle.java.home and uses it for the project.
Then it checks the JAVA_HOME environment variable.
Then it checks the closest appropriate JDK version for the existing Gradle version.
There are related requests:
IDEA-240044 Path Variable for the default project JDK
IDEA-151340 Allow path variables to reference environment variables

How to set up a relative path to a portable JDK in IntelliJ IDEA portable?

Since I code on several computers, I decided to install IntelliJ IDEA portable on my USB drive right next to my portable JDK installation. Now I would like to point to that JDK with a relative path inside IntelliJ so the IDE can find it everywhere. Unfortunately, it seems like I can only store the absolute path to the JDK, although the drive letter of my USB may change from device to device. Is there any way around this?
JDK paths are stored in the IDE settings vs the project settings and currently there is no way to specify the JDK path relatively, it will always use the absolute path.
Please vote for this feature request if you need this feature in the future IntelliJ IDEA updates.

Change intellij JVM

I saw a comment about fixing an issue with the Intellij
"The problem should not occur if you switch Java used by the IntelliJ IDEA from OpenJDK bundled with IDEA to Oracle JVM. At least this can work as a workaround."
How can I change the JVM in Intellij ?
Set an environment variable to tell IntelliJ what JVM to use for the IDE.
Go into Control Panel...System...Advanced System Settings. Click the "Advanced" tab, then click the "Environment Variables" button to edit.
Add a new user variable -
"IDEA_JDK" for a 32-bit JVM, or "IDEA_JDK_64" for a 64-bit JVM. Set the variable to point to the directory of the JDK you want IntelliJ to use (e.g., "C:\Java\jdks\1.8x64" or similar)
Restart IntelliJ.
The procedure is described here:
Open the Find Action popup using ctrl+shift+A
Type switch and select Switch Boot JDK
Select an existing JDK in the dropdown (use ... to select a custom path)
Reboot the IDE

Intellij project between Windows and Linux - use the 'default system provided' JDK?

I've got two dev workstations, one running Windows, the other running Linux. I work on a Java project using Intellij on both. Both platforms have the Oracle JDK 7 installed in the default locations.
For some annoying reason, every time I switch platforms, I need to update the project configuration to specify what JDK it should be using. In the project's "Project SDK" setting, there's a JDK selection which includes two entries - 1 for a JDK in c:\Program Files\Java\jdk_1.7 and the other for a JDK in /usr/lib/jvm/java-7-jdk/. If I open the project on Linux, I have to specifically set the Project JDK to be the second. If I save the project, close, commit, and then checkout and open on Windows, it complains it can't find the JDK, and I have to manually set it to the Windows version.
Why can't Intellij figure this out automatically? I appreciate that testing against multiple installed JDKs is a useful feature, but is there a way to tell a project to 'just use the default JDK'?
You need to have your JDK configurations to have the same name, lile 1.6 or 1.7. Project file references JDK by its name only so it will work out of the box in all IDEA installations on different operation systems, the only requirement is that there is JSDK defined under exactly the same name.

gradle doesn't work in Intellij - problems with JAVA_HOME

I can run gradle from a command line to see its version.
I can run, compile and debug a grails app in IntelliJ (version 10.0 or version 10.2)
I installed the IntelliJ Gradle Plugin.
Whenever I try to do anything with gradle from within Intellij I get an error as follows:
Executing command: "tasks"
Failed to connect to gradle process for command 'tasks'
ERROR: JAVA_HOME is set to an invalid directory: C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.0\jre
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
But in my environment I have JAVA_HOME set to the proper JDK in a different directory. Plus when I look in IntelliJ for the project, it also shows the JDK in the proper JDK location. I cannot find anything that attempts to point the JDK to the Intellij JRE location.
Any ideas please?
IntelliJ uses its own jre.
to force IntelliJ to use it, you need to set the environment variable IDEA_JDK to point to your JDK.
then simply restart intellij and gradle gui plugin should now work.
Man I had so much trouble with this as well, and I don't remember having this much trouble before. I think they changed something. Here are the incantations which got it working for me on Mac OS X 10.11.5, both with Java and Gradle on IntelliJ 2016.1
Here's the summary: install the latest Java JDK from Oracle, add the java_home value to $JAVA_HOME and set that value to $IDEA_HOME (IntelliJ's variable for defining which JDK to use), install gradle (optional) using homebrew, then define the project SDK in IntelliJ.
Here it is broken down from the very beginning of a clean install:
1. Download Java from Oracle's Download Page
2. Use homebrew to install gradle
IntelliJ ships with its own version of Gradle, so this is really optional, and is helpful if you want to use Gradle outside of IntelliJ.
`brew update && brew install gradle`
3. Set the env variables
Paste the following into ~/.profile. These values will work regardless of which version of java or gradle you have installed. Don't set the GRADLE_HOME if you didn't install the standalone gradle.
export JAVA_HOME=$(/usr/libexec/java_home)
export IDEA_JDK=$JAVA_HOME
export GRADLE_HOME=/usr/local/opt/gradle/libexec
4. Set the environment variable to occur at application launch so that IntelliJ sees is using OS X's launchctl program:
launchctl setenv JAVA_HOME $(/usr/libexec/java_home)
5. Define the project SDK
Use the project settings window in IntelliJ to define the project SDK (I don't see this option anywhere else in the global IntelliJ preferences window, this has to be done in the project settings).
6. Wait for the indexes to update, then close and re-open IntelliJ. You should now be able to build the program.
if you are using Intellij version 10.x you should not install any Plugin to run a gradle script.
All you have to do is to go to the Gradle setup (File -> Settings -> Gradle) and set the Gradle Home folder (the location of your Gradle installation, eg. C:\tools\gradle).
You should be able to select a Gradle build file and run it.
Point your JAVA_HOME to JDK, not to JRE.
I think this error might be caused by an install bug with IntelliJ IDEA. When I look at the installed folder referred to in the error message on my filesystem:
C:\Program Files (x86)\JetBrains\IntelliJ IDEA 10.0\jre
I see the jre folder but then another jre folder beneath that one which contains the bin and lib folders of the jre:
jre
jre
bin
lib
I copied bin and lib up a level into the first jre folder, and that fixed this error for me.