I have a gradle project with multiple modules. In one of the modules I have a standalone java class and the src directory structure is like,
Class/Student/java/com/test/Sample.java
package com.test;
public class Sample {
public static void main(String args[]){
System.out.println("Test");
}
}
When I run the Sample class with my run config. I always have the error as ,
Error: Could not find or load main class test.Sample
I could see the Sample.class file existing in the current directory, after compilation !
I also tried compiling & running the class outside intellij, from terminal. I have the same error.
I removed the package declaration from the file and then compile & run it from terminal, it works.
public class Sample {
public static void main(String args[]){
System.out.println("Test");
}
}
Already tried the solutions mentioned in these posts, but no luck,
- Error: Could not find or load main class in intelliJ IDE
- Unable to find or load Main Class in Intellij 2019.4
Currently using IntelliJ 2022.3.2 (Ultimate Edition). The same project has been imported by another user in eclipse, everything works. He could run the standalone java class successfully.