To create a new class, press ⌘N on MacOS or Alt+Insert on Windows or Linux on the directory in the Project Window, and select “Java class”. When creating a new class, we can type the whole package path, separated by dots, followed by the class name, and IntelliJ IDEA will create the package and the Java file.
The main() method can appear in any class that is part of an application, but if the application is a complex containing multiple files, it is common to create a separate class just for main(). The main class can have any name, although typically it will just be called "Main".
We can type a short sequence, like psvm , and have IntelliJ IDEA generate things like the public static void main method. We can even create our own live templates for code snippets we commonly use. If we put the cursor inside the main method, we can run it by using ⌃⇧R, or Ctrl+Shift+F10 on Windows.
Select the folder containing the package tree of these classes, right-click and choose "Mark Directory as -> Source Root"
The documentation you linked actually has the answer in the link associated with the "Java class located out of the source root." Configure your source and test roots and it should work.
https://www.jetbrains.com/idea/webhelp/configuring-content-roots.html
Since you stated that these are tests you should probably go with them marked as Test Source Root instead of Source Root.
Here is the complete procedure for IDEA IntelliJ 2019.3:
File > Project Structure
Under Project Settings > Modules
Under 'Sources' tab, right-click on 'src' folder and select 'Sources'.
Apply changes.
Sometimes under the current automatically configured sources root you need to specify the module classpath:
Use classpath of module
pulldown see if there is a sub directory that has your main class under it. If so, select it.I also faced another issue: the main method has to have arguments
This way is incorrect, Intellij will not let you select main method.
public class yourClass() {
public static void main() {
This way is CORRECT and Intellij will let you select it
public class yourClass() {
public static void main(string[] args) {
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With