eclipse 如何使用eclipse快速找到java项目中的main()?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16945474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to quickly find the main() in java project using eclipse ?
提问by URL87
In a case I have the src folder of project with a lot of classes in it , how could I detect which is the class with the main()
that the project running start with ?
在一种情况下,我有项目的 src 文件夹,其中包含很多类,我怎么能检测哪个是main()
项目运行开始的类?
采纳答案by NINCOMPOOP
- 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;
- 打开要从中运行类的项目;
- 在主窗口中:运行 -> 打开运行对话框...(运行配置);
- 在左侧部分打开您的项目所属的项目类型(如果它是主要功能,则在您的情况下将是“Java 应用程序”);
- 在此类别下,您应该看到所有“可执行”类名称;
回答by Andy Thomas
From the Eclipse IDE menu, select Search>Java ....
从 Eclipse IDE 菜单中,选择Search>Java ...。
In the dialog, enter:
在对话框中,输入:
- "main" as the search string.
- "Method" in the "Search For" box.
- "Declarations" in the "Limit to" box.
- “main”作为搜索字符串。
- “搜索”框中的“方法”。
- “限制于”框中的“声明”。
This gives you a convenient, hierarchical list in the "Search" view linking to all the classes with main() methods.
这在“搜索”视图中为您提供了一个方便的分层列表,通过 main() 方法链接到所有类。
Click on one of these to navigate to the class. Then right-click Run Asor Debug Asto run.
单击其中之一以导航到该类。然后右键单击Run As或Debug As来运行。
回答by fge
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.
问题是在 jar 中,您不仅限于一种main()
方法。main()s
在“生产”源和“测试”源等中,可能有几个分散在不同的类中。
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.
如果您确定可以使用 启动从该项目构建的 jar java -jar the.jar
,那么这意味着META-INF/MANIFEST.MF
有一个Main-Class
条目:您应该在那里查找类名。
Otherwise, you have to search for methods named main
with a classical find tool... (see @AndyThomas' answer)
否则,您必须搜索main
使用经典查找工具命名的方法...(请参阅@AndyThomas 的回答)
回答by Konstantin Yovkov
If there is a META-INF/MANIFEST.MF
file, you can search for Main-Class
in it.
如果有META-INF/MANIFEST.MF
文件,您可以Main-Class
在其中搜索。
回答by David
You can use
您可以使用
Run -> Run Configurations (Alt + R + N)
or
或者
Run -> Debug Configurations (Alt + R + B)
回答by sanbhat
Your_Eclipse_Project -> Export... -> Runnable Jar File...
Your_Eclipse_Project -> 导出... -> 可运行的 Jar 文件...
here the top section of the dialog should list down all the classes having main()
method, something like below
这里对话框的顶部应该列出所有具有main()
方法的类,如下所示
Alternatively,
或者,
Your_Eclipse_Project -> Run As... -> Java Application
Your_Eclipse_Project -> Run As... -> Java 应用程序
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.
将启动一个对话框,其中列出了所有可以选择和运行的主要类型。这也将搜索您的项目引用的所有 jar。