Reputation: 622
I have a project in IntelliJ Idea that uses jdk 8. In my system I have many jdk installed for development. Every time I create a new terminal window inside IntelliJ, the latest system jdk (jdk 10) is used and not the project one (jdk 8 in this case) and I have to switch manually. Of course I realise the error only after some build which requires jdk 8 does not work properly.
Is there a possibility to set the jdk used in IntelliJ terminal?
Upvotes: 1
Views: 4059
Reputation: 1
As per other answers - doesn't look like its supported but in the meantime I thought I would post a workaround that solves the poster's problem:
my solution is to create a shell script that launches with the terminal profile:
my solution is in powershell as I found it an interesting exercise to solve. The same can be achieved in Unix as easily if not easier.
# $Home\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
$ideaDir = "./.idea"
if (Test-Path -Path $ideaDir)
{
$jdksDir = "$Home\.jdks"
$match = Select-String -Path "$ideaDir/misc.xml" -Pattern "project-jdk-name=`"(.*?)`" "
$jdkName = $match.Matches.groups[1].value
[array]$jdks = ls -Directory -Name $jdksDir
$success = 0
foreach( $jdk in $jdks) {
if($jdk.Contains( $jdkName )) {
$pathBlock = "$jdksDir\$jdk\bin"
echo "adding $pathBlock to path"
$env:Path = "$pathBlock;" + $env:Path
$success = 1
break
}
}
if( $success -eq 0) {
"failed to add jdk $jdkName to path"
}
}
Some assumptions have been made here:
Upvotes: 0
Reputation: 2481
For anyone else who stumbles on this question, here is how I resolved a similar issue:
Maybe this is just my company's security*, but when a JDK is installed with an .exe, something like the following path is created and added to the root of the %path% variable: C:\Program Files\Common Files\Oracle\Java\javapath
On that path you'll find a 'java' executable for the installed version of java.
The fix was to simply uninstall that version of java, via the system settings.
*
I mean that I was unable to see the 'true' path variable, may have been my company's security.
Upvotes: 0
Reputation: 446
Check Preferences->Tools->Terminal do determine the used shell implementation.
Change the shell path or change your environment settings with the used shell to take effect e.g. for setting JAVA_HOME
and PATH
.
You can even use the "shell integration" flag to load a custom rc config file. Please check the IntelliJ documentation for this.
You are not able to use the configured projects JDK in a dynamic way. If you need this, please file an enhancement request to Jetbrains.
Upvotes: 1
Reputation: 1
You need to change the SDK version in project structure. You can change it through IntelliJ navigation top bar, by following this path:
File > Project Structure > Project tab > Project SDK
Upvotes: 0