简体   繁体   English

蚀“运行为”不显示任何选项

[英]eclipse “run as” not showing any option

I would like to run a java project by right clicking the file containing my Main method. 我想通过右键单击包含Main方法的文件来运行Java项目。 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 (ie no 'Run as' options) when trying to build the project using my Ant xml. 当尝试使用我的Ant xml构建项目时,我遇到了同样的问题(即没有“运行方式”选项)。 Previously I would right click the build.xml file and select 'Ant build'. 以前,我将右键单击build.xml文件,然后选择“ 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 谢谢

Main method is the entry point for the application to ru. 主要方法是应用程序进入ru的入口。 Make sure your main method definition is correct. 确保您的主要方法定义正确。 You may be having a main method, which is different from what JVM expects. 您可能有一个main方法,它不同于JVM期望的方法。 Correct definition of main method should look like this: 正确的main方法定义应如下所示:

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. 此定义的任何更改都将使您的主要方法成为不同的方法,并且JVM将无法在要运行的代码中找到入口点。

Also your class containing the main method should be a public class and the corresponding file name should be same as that of class. 另外,包含main方法的类应该是公共类,并且对应的文件名应与该类的文件名相同。

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:) 因为文件夹不是项目,并且运行/调试作为Java应用程序只会在它属于我想的项目时显示,但是不确定,这可能对您有帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM