Search code examples
javaintellij-ideaclasspathclassnotfoundexception

Intellij IDEA: "Could not find or load main class" if Dependencies Storage Format is changed to "Eclipse"


I wrote a simple "Hello World" program in my test project in Intellij IDEA 2020.3.2 (Ultimate):

public class Test {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }

}

Everything works fine when running Test.main() with the default configuration. Now, if I go to File | Project Structure... | Project Settings | Modules and change Dependencies storage format to Eclipse (.classpath), a .classpath file and an .eml file are created (the .iml file is still there, but it doesn't affect the following problem, whether it's there or not). If I now run Test.main(), the following error output is returned in the IDE console:

"C:\Program Files\Java\jdk-15.0.1\bin\java.exe" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2020.3.2\lib\idea_rt.jar=51699:C:\Program Files\JetBrains\IntelliJ IDEA 2020.3.2\bin" -Dfile.encoding=UTF-8 Test
Error: Could not find or load main class Test
Caused by: java.lang.ClassNotFoundException: Test

Process finished with exit code 1

What might be the the problem? I tried these solutions, but they seem to have no effect here. Could there be a problem with the Windows 10 environment variables? The given CLASSPATH value here is .;.


Solution

  • Thanks for the report, it appears to be a bug in IntelliJ IDEA project configuration when the dependencies format is set to Eclipse. IDE loads the project incorrectly and the sources root configuration is lost, therefore compiler doesn't get the correct information about the source files and nothing is produced in the output directory. Classpath doesn't contain any classes and the execution of the main class fails since it doesn't exist in the output (classpath).