how to setup “Main Class” in “Run Configurations” in Eclipse

前端 未结 6 1356
甜味超标
甜味超标 2020-12-02 00:19

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

C:\\Desktop\\project1\\src\\com\\pre\\moveposi         


        
相关标签:
6条回答
  • 2020-12-02 00:42

    if the method has a main method look down the Package Explorer, select the file you want to run (that has a main) right click it, selected Run As, select Java application.

    0 讨论(0)
  • 2020-12-02 00:47

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

    If only one of your classes has Main() function, setup that class.

    0 讨论(0)
  • 2020-12-02 00:48

    if it's a maven project look for your class under target/classes folder. You certainly open the automatic build also.

    0 讨论(0)
  • 2020-12-02 00:49

    Under Run Configurations, you can create multiple launch configurations under 'Java Application'. Create one with project as project1 and Main Class as com.pre.moveposition1 and try hitting Run.

    You should create one more for com.pre.moveposition2 if you want to run that one.

    Note: It is best practice to name classes to start with caps letters.

    0 讨论(0)
  • 2020-12-02 00:56

    Put the (fully qualified) name of the class containing main. For example, if you want to use moveposition2's main (and not moveposition1's) then you'd enter:

    com.pre.moveposition2
    

    Also, clicking on "Search..." should give you a list of classes that contain main() methods that you can choose from.

    0 讨论(0)
  • 2020-12-02 01:02

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

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

    0 讨论(0)
提交回复
热议问题