Search code examples
javaintellij-ideaenvironment-variables

IntelliJ - Cannot run program java.exe. CreateProcess error=2. The system cannot find the file specified


I'm reaching out for a bit of help in trying to figure out why my IntelliJ does not run for a project.

I am using IntelliJ 2023.1.5 Community Edition Build #IC-231.9392.1, built on July 25, 2023

I have multiple projects all but one running jdk 1.8.0 in C:\Program Files (x86)\Java, all were working fine until I started a new project using corretto 17.0.7, which was initially placed here C:\Users\Me.jdks\jbr-17.0.7\bin\java.exe, but is now in the Java folder with the previously mentioned jdk

The new project was working as it should, then I needed to swap back to one of the other projects. At this point when I try to run the older project I get the following error:

Cannot run program "C:\Users\Me\.jdks\jbr-17.0.7\bin\java.exe" (in directory "C:\Users\Me\AppData\Local\JetBrains\IdeaIC2023.1\compile-server"): CreateProcess error=2, The system cannot find the file specified.

This error occurred both before and after the directory change of corretto 17.0.7, it never occurred prior to the creation of the new project

I have went through my older project and there is nothing referencing 17.0.7 that I can see, in the places where I know a jdk can be set

Project Settings - Project Project Settings - Project

Project Settings - Modules Project Settings - Modules

Project Settings - SDKs Project Settings - SDKs

Run/Debug Config Run/Debug Config

The below 2 do show a different JDK to the one I'm using, I'm not entirely sure it matters as I haven't changed them and the older project used to work fine prior to the new one being started.

Java Runtime Environment Java Runtime Environment

Java Registry Java Registry

Other things I have tried Invalidate the cache of IntelliJ, reboot the machine

Trying to find the cause/solution led to to also try Adding the -Didea.dynamic.classpath=true in Help | Edit Custom VM Options and restart the IDE - Did not work (Part of this question https://youtrack.jetbrains.com/issue/IDEA-285090)

As per this question https://stackoverflow.com/questions/31238144/in-intellij-idea-14-1-4-cannot-run-program-c-program-files-x86-java-jdk1-8 the answer asks If your path JAVA_HOME is OK:

File → Settings → Build, Execution, Deployment → Build Tools → Maven → Runner Set to "use JAVA_HOME (...Path...)" Maven Runner This is set to the jdk path albeit not JAVA_HOME, I did try adding a JAVA_HOME Environment Variable here but no change so deleted it out.

For Part 2 of the answer, I do not have a File → Other Settings → Default Project Structure to check

The older project works on other machines fine, a second user also configured their machine to use my new project and they can swap between the new and old project with no issues.

So I guess my question would be based on the error message I get when trying to run the older program - What could have been changed to it now be causing it to look here for the java.exe ("C:\Users\Me\.jdks\jbr-17.0.7\bin\java.exe"), when I didn't do anything to the older programs setup ?

I cannot for the life of me figure out what the solution is, hence why I am coming here to see if anyone else can provide assistance.


Solution

  • I would probably begin by removing any SDK in the IDE (you seem to have tons) that refers to a non-existent jdk. You really need to synch what you have installed with what your IDE says it can deliver