Search code examples
javaeclipsem2eclipse

Cannot run as java application in Eclipse, even have correct main() class


I get confusing with Eclipse, when I import a project from Git, then I click on a java file, which has correct main function like:

  public static void main(String[] args) throws Exception { }

and the outside class has same name with java file. But when I right click the java file, only have "run on server" or "run configuration" option, no "run as java application" like normally. Even if I copy a java file which I can run as java application from different project to this project (no error) then it do not have this option ??? I am quite sure it is nothing to do with the code. I checked the code, totally the same and should be able to run.(I am aware of similar questions on the website but I checked and my problem is not there)

So is there any extra steps I need to do with this project (like maven build ? -> I tried this but also can't run, how to run it properly ?) to have this option again ???

Really confusing !


Solution

  • If the project is already imported in your workspace, Right click on your and Configure > Convert to Maven... This will enable the Maven builder and force m2e configurators to setup all the required project natures on your project.

    You can also install the m2eclipse-git connector to streamline the "import maven project from git" process. It should be available from Preferences > Maven > Discovery > Open Catalog.

    Once it's done, you should import your project via Import...> Maven > Checkout Maven Projects from SCM