Domanda

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

È stato utile?

Soluzione

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.

Altri suggerimenti

If your project folder is in another project, aka. belongs to a parent project, try:

Right click the project which main class belongs too, and click "import as new project" or something like that, then there should be a new project in the project Explorer at the bottom of the list.

Then right click the main class file in that project.

Because a folder is not a projcet, and run/debug as java application will only show up when it belongs to a project I suppose, but not sure, may this would help u:)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top