0

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 .;.

howlger
  • 31,050
  • 11
  • 59
  • 99
TiMauzi
  • 190
  • 1
  • 3
  • 16
  • Does https://stackoverflow.com/a/42660624/104891 help? – CrazyCoder Mar 11 '21 at 19:26
  • @CrazyCoder I tried/checked all these approaches. Unfortunately, they didn't solve the problem. Plus, the Exception in the link seems to be of a different nature than the one in my problem, since the main method seems to be found in that other question. I want to emphasize that the compilation and running works as usual if the *Dependencies storage format* is set to Intellij IDEA. For the usage of a certain library, I'd like to use a `.classpath` file instead, though. – TiMauzi Mar 11 '21 at 23:05
  • Please file a bug at https://youtrack.jetbrains.com/newIssue?project=IDEA with the sample project to reproduce attached and the logs (Help | Collect Logs and Diagnostic Data). – CrazyCoder Mar 11 '21 at 23:06
  • @CrazyCoder Done, thank you: https://youtrack.jetbrains.com/issue/IDEA-264135 – TiMauzi Mar 11 '21 at 23:24

1 Answers1

1

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).

CrazyCoder
  • 389,263
  • 172
  • 990
  • 904
  • 1
    This doesn't qualify as an answer, since you haven't provided a solution. – Ojonugwa Jude Ochalifu Jun 25 '22 at 10:25
  • @OjonugwaJudeOchalifu There is no solution until this bug is fixed. As a workaround do not store dependencies in Eclipse format, use IntelliJ IDEA project, Gradle or Maven project instead. – CrazyCoder Jun 25 '22 at 23:34