111

I am using IntelliJ IDEA 13.1.4 and also tried the latest release 14.

Running SBT I get the following error:

Error:Cannot determine Java VM executable in selected JDK

I have JDK 1.7 installed on my machine and on PATH.

In the logs (~/Library/Logs/IntelliJIdea14/idea.log on MacOS) there's the following stack trace:

2014-11-03 11:22:05,054 [4896641]   WARN - nal.AbstractExternalSystemTask - Cannot determine Java VM executable in selected JDK
com.intellij.openapi.externalSystem.model.ExternalSystemException: Cannot determine Java VM executable in selected JDK
    at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$10.apply(SbtExternalSystemManager.scala:97)
    at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$10.apply(SbtExternalSystemManager.scala:97)
    at scala.Option.getOrElse(Option.scala:120)
    at org.jetbrains.sbt.project.SbtExternalSystemManager$.executionSettingsFor(SbtExternalSystemManager.scala:96)
    at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$getExecutionSettingsProvider$1.apply(SbtExternalSystemManager.scala:54)
    at org.jetbrains.sbt.project.SbtExternalSystemManager$$anonfun$getExecutionSettingsProvider$1.apply(SbtExternalSystemManager.scala:54)
    at org.jetbrains.sbt.package$$anon$3.fun(package.scala:29)
    at org.jetbrains.sbt.package$$anon$3.fun(package.scala:28)
    at com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil.getExecutionSettings(ExternalSystemApiUtil.java:590)
    at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.a(ExternalSystemFacadeManager.java:201)
    at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.a(ExternalSystemFacadeManager.java:178)
    at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager.doInvoke(ExternalSystemFacadeManager.java:133)
    at com.intellij.openapi.externalSystem.service.ExternalSystemFacadeManager$MyHandler.invoke(ExternalSystemFacadeManager.java:270)
    at com.sun.proxy.$Proxy57.getResolver(Unknown Source)
    at com.intellij.openapi.externalSystem.service.internal.ExternalSystemResolveProjectTask.doExecute(ExternalSystemResolveProjectTask.java:48)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:137)
    at com.intellij.openapi.externalSystem.service.internal.AbstractExternalSystemTask.execute(AbstractExternalSystemTask.java:123)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$2.execute(ExternalSystemUtil.java:475)
    at com.intellij.openapi.externalSystem.util.ExternalSystemUtil$3$1.run(ExternalSystemUtil.java:543)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$TaskRunnable.run(ProgressManagerImpl.java:609)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$7.run(ProgressManagerImpl.java:410)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl$3.run(ProgressManagerImpl.java:194)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.a(ProgressManagerImpl.java:281)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:233)
    at com.intellij.openapi.progress.impl.ProgressManagerImpl.runProcess(ProgressManagerImpl.java:181)
    at com.intellij.openapi.application.impl.ApplicationImpl$10$1.run(ApplicationImpl.java:640)
    at com.intellij.openapi.application.impl.ApplicationImpl$8.run(ApplicationImpl.java:405)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    at org.jetbrains.ide.PooledThreadExecutor$1$1.run(PooledThreadExecutor.java:56)

What can be the reason for this?

Jacek Laskowski
  • 64,943
  • 20
  • 207
  • 364
Zuriar
  • 8,864
  • 14
  • 46
  • 76
  • It's likely that you have JRE in `Project SDK` for the project defined. Could you check Project Settings for the project in question and see the settings under Project? – Jacek Laskowski Aug 08 '14 at 14:26
  • I found that I needed to **Invalidate Caches** as described [in this answer](http://stackoverflow.com/a/4482827/77567). – rob mayoff Jul 15 '16 at 18:54

11 Answers11

205

You should be able to work it around by setting the jdk from the settings not from the open/import project dialog.

From the welcome screen, go to Configure -> Project defaults -> Project structure and add the jdk.

enter image description here

Opening the sbt project should work well then.

Found solution from here

Jacek Laskowski
  • 64,943
  • 20
  • 207
  • 364
Prabu
  • 2,386
  • 1
  • 13
  • 9
25

Another way to set JDK is from your current module/project settings (for your current project)

PickOpen Module Settings from project context menu (or default hit F4),
then from left tab select Project and point correct Project SDK on dropdown.

enter image description here

michalczukm
  • 8,196
  • 5
  • 35
  • 47
21

The issue is usually caused by a wrong JDK version in ".idea/sbt.xml", e.g.:

<option name="jdk" value="1.7" />

This option is not updated accordingly when the Project SDK is changed, see SCL-10085. If you have the other JDK (1.7 in my example) generally configured, no error will occur, but the Project SDK will silently be changed back. Otherwise, this error occurs.

The problem can easily be resolved by manually editing the value in ".idea/sbt.xml" to the right JDK version.

F30
  • 816
  • 7
  • 18
7

Same error also occurs when you try to do a refresh in "SBT tasks".

Open

Preferences -> Language & Frameworks -> Scala Compiler Server

Turn on

Run compile server (in external build mode)

Once you done with refreshing the project, turn it off again to enable hotswapping back when you change your code in the editor.

Onur Aktaş
  • 410
  • 4
  • 8
5

I had to open Settings -> Language & Frameworks -> Scala Compiler Server

Then set the JVM SDK there, which was <No SDK>.

This was in addition to setting the Project SDK in Project Structure -> Project.

See the screenshot here.

1

IntelliJ 13.1.6 > File > Project Structure > set Project SDK

soheildb
  • 1,116
  • 7
  • 9
1

I got the same problem after I delete Java1.6 and Java1.7 from Project Settings(with Java8 as default).

Finally I solve the problem by change SBT JVM config to Custom Java(Settings -> Build, Execution, Deployment -> Build Tools -> SBT).

1

For me the above suggestions did not help for some reason. However, I did figure out that under Project Defaults > Project Structure (Welcome screen) my default Project SDK was set to the Go SDK.

What worked for me was setting this default SDK to the Java JDK.

edin0x
  • 41
  • 5
0

For me, I had selected the JDK in "Open Module Settings" > Module > Dependencies > Module SDK. However, SBT was looking for JDK at project level which is set in "Open Module Settings" > Project > Project SDK as @michasm has pointed out above

Shiva
  • 95
  • 7
0

The latest Nightlies of the Scala plugin change how the project JDK is set, which should solve this in most cases. Let me know if it still breaks on some cases.

Justin Kaeser
  • 5,498
  • 25
  • 42
0

This happened to me in a multi-language project when my primary module's Project SDK was Python and I was trying to add a secondary module that was JDK (importing an sbt project).

I had to temporarily switch the primary module's Project SDK to JDK in order to add the sbt module. I then had the ability to go back and change each module to the correct SDK.

Bryan Johnson
  • 591
  • 4
  • 5