Search code examples
javaeclipseantpreferencesfile-association

eclipse "run as" not showing any option


I would like to run a java project by right clicking the file containing my Main method. When I hover over the 'Run as' option I get an empty list. I can still use the "Run configurations" and get the project running.

I have the same problem (i.e no 'Run as' options) when trying to build the project using my Ant xml. Previously I would right click the build.xml file and select 'Ant build'. My workaround here is to add the builder into the project properties

I suspect I changed some definitions of the file type association, but don't know how to verify if this is indeed the problem. Any suggestions? Thanks


Solution

  • Main method is the entry point for the application to ru. Make sure your main method definition is correct. You may be having a main method, which is different from what JVM expects. Correct definition of main method should look like this:

    public static void main(String args[])
    

    Any change in this definition will make your main method to be a different method and JVM will not be able to find the entry point in your code to run.

    Also your class containing the main method should be a public class and the corresponding file name should be same as that of class.