IntelliJ IDEA 2021 How to run the main method of a single java class when other JAVA classes have errors

Development tools: IntelliJ IDEA 20213.3

Operating system: windows 10

Sometimes in order to quickly test a certain function or temporarily forget the usage of a certain method, we will simply use the main method to test. When executing the main method in Eclipse, you can execute a class separately. Although other classes have errors, they will There is a prompt message, but it does not affect the execution of the main method. But in IDEA, if there are errors in other classes, the main method of the correct java class will not run. You can solve this problem by following these steps:

1. Open Edit Configurations

Find the Run menu, open Edit Configurations, or enter it from starting Tomcat

Select the class to be set on the left, and click the blue font "Modify options" on the right

2. After clicking, a selection page will pop up, select "Add before launch task"

3. Select "Build, no error check" in the second interface, and then delete "1.Build", 

The final effect is as follows:

 4. Just re-execute the classes that need to be run.

Unexpected situation: After running the main function according to the above operation, it prompts: "Error: The main class cannot be found or cannot be loaded". Need:

 You need to recompile the class. In the menu Build, select Recompile, (shortcut key Ctrl+Shift+F9)

Guess you like

Origin blog.csdn.net/caicaimaomao/article/details/125103379