Error while running Java app

2020-07-08 05:06发布

问题:

The log shows this

"error=2, No such file or directory"

"Cannot run program /Applications/IntelliJ IDEA.app/Contents/jre/jdk/Contents/Home/bin/java" (in directory "/Users/.. " and a path to a directory that exists.

I could replicate the error running a "hello world" app without any type of dependencies and configs (no maven, no spring).

I'm using Intellij 2016, and OSX El Capitan

回答1:

The problem was with the SDK that was referencing the one that is bundled inside Intellij.

I could solve it by changing the sdk and referencing the one outside Intellij. This can be done going to File > Project Structure > SDKs and in "JDK Home Path" put the path to the SDK (in my case /Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk/Contents/Home).