How to set up "Main Class" in "Run Configurations" in Eclipse

In a Java project, there are two java files with the main method. The absolute paths for these two java files are:

C:\Desktop\project1\src\com\pre\moveposition1.java 

AND

 C:\Desktop\project1\src\com\pre\moveposition2.java 

When I try to configure the "Main class" parameter in the "Run configuration", what should I configure?

enter image description here

+8
java eclipse
source share
6 answers

Put the (full) name of the class containing main. For example, if you want to use moveposition2 main (rather than moveposition1), you would enter:

 com.pre.moveposition2 

In addition, clicking on "Search ..." should give you a list of classes that contain the main () methods that you can select.

+3
source share

If both classes have a main() method, you can only run one at a time, since they effectively represent two different programs.

So, in the launch configuration, select either moveposition1 or moveposition2 . If you later want to run another, just right-click it and select Run As...->Java Application . You will now have two launch configurations for your project.

+2
source share

In the Run Configuration section, you can create several run configurations in the Java Application. Create a project with project1 and a main class like com.pre.moveposition1 and try running Run.

You must create another one for com.pre.moveposition2 if you want to run this one.

Note. It is best to name classes to start with the letters of the letters.

0
source share

If both classes contain the Main () function, you must configure the class with which you want to start your program.

If only one of your classes has a Main () function, configure this class.

0
source share

if the method has the main method, browse the package explorer, select the file you want to run (with the main one), right-click on it, select "Run As", select the Java application.

0
source share

if the maven project is looking for your class in the target / classes folder. You also open auto-build.

0
source share

All Articles