score:11

Accepted answer
  • open the project you want to run class from;
  • in main window: run -> open run dialog...(run configurations);
  • in the left section open the project type your project belongs to (if it's main function it would be "java application" in your case);
  • under this category your should see all the "executable" class names;

score:1

your_eclipse_project -> export... -> runnable jar file...

here the top section of the dialog should list down all the classes having main() method, something like below

enter image description here

alternatively,

your_eclipse_project -> run as... -> java application

will launch a dialog, which lists down all the main types which can be selected and run. this will search through all the jars referenced by your projects too.

score:2

if there is a meta-inf/manifest.mf file, you can search for main-class in it.

score:2

you can use

run -> run configurations (alt + r + n)

or

run -> debug configurations (alt + r + b)

example of debug configuration

score:5

the problem is that in a jar, you are not limited to one main() method. there can be several main()s scattered across different classes, in "production" sources as well as in "test" sources etc.

if you know for sure that the jar built from this project can be launched using java -jar the.jar, then it means the meta-inf/manifest.mf has a main-class entry: you should look in there for the class name.

otherwise, you have to search for methods named main with a classical find tool... (see @andythomas' answer)

score:8

from the eclipse ide menu, select search>java ... .

in the dialog, enter:

  • "main" as the search string.
  • "method" in the "search for" box.
  • "declarations" in the "limit to" box.

this gives you a convenient, hierarchical list in the "search" view linking to all the classes with main() methods.

click on one of these to navigate to the class. then right-click run as or debug as to run.


Related Query

More Query from same tag