java 如何在大项目中找到 main() 函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6368428/
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 find main() function in a big project
提问by Adrian
I never used Java, but I'm looking over a big server project writting in Java with Eclipse.
My question is, how can I find the main() function, is there an easy way, or I have to search for it in every .java file ?
我从未使用过 Java,但我正在查看使用 Eclipse 用 Java 编写的大型服务器项目。
我的问题是,如何找到 main() 函数,有没有简单的方法,或者我必须在每个 .java 文件中搜索它?
采纳答案by drekka
You will have to do a code base wide search as it could be in any file. Having said that, many server based project do not have a main() function at all. The server provides the infrastructure and only looks for classes which inherit from specific other classes or implement certain interfaces or are mentioned in certain config files. All of this depends on the server and the technologies employed.
您将必须进行代码库范围的搜索,因为它可以在任何文件中进行。话虽如此,许多基于服务器的项目根本没有 main() 函数。服务器提供基础结构,仅查找从特定其他类继承或实现某些接口或在某些配置文件中提及的类。所有这些都取决于服务器和所采用的技术。
You need to find out what your server is, what technologies have been used in the java project and how it was setup.
您需要了解您的服务器是什么,java 项目中使用了哪些技术以及它是如何设置的。
回答by Andreas Dolk
- Use eclipse's build in search function and search for "
main(
" in all projects java files (= entire workspace) - Look for theapplication jar and look at it's manifest file, it may contain the name of the main class
- Look for scripts that are used to start the application. You eventually find the
java
call that starts the application (a parameter is the main class) - Look for build scripts (
build.xml
). Eventually they contain some jar, install or deploy target where startup scripts are autogenerated or manifest files are written. The main class should be named there.
- 使用 Eclipse 的内置搜索功能并
main(
在所有项目 java 文件(=整个工作区)中搜索“ ” - 查找的应用罐子,看看它的清单文件,它可能包含主类的名称
- 查找用于启动应用程序的脚本。你最终找到
java
启动应用程序的调用(一个参数是主类) - 查找构建脚本 (
build.xml
)。最终它们包含一些 jar、安装或部署目标,其中自动生成启动脚本或编写清单文件。主类应该在那里命名。
BTW - If the big server projectis a server based application, say the final build result is a waror an earfile, then the entry point doesn't have to be a static main
method. Then it might not even have onesingle starting point.
顺便说一句 - 如果大型服务器项目是基于服务器的应用程序,比如最终构建结果是War或耳朵文件,那么入口点不必是静态main
方法。那么它甚至可能没有一个起点。
回答by Daniel Lundmark
Well, if nothing else, you could use the Search menu, Java, and use "main(String[])" as the search string. Search for: Method, Limit To: Declarations and Search In: Sources. That will help your search.
好吧,如果不出意外,您可以使用“搜索”菜单、Java,并使用“main(String[])”作为搜索字符串。搜索:方法,限制为:声明和搜索:来源。这将有助于您的搜索。
If you have a run configuration in Eclipse, you can look in that and see which class and method is being invoked.
如果您在 Eclipse 中有一个运行配置,您可以查看它并查看正在调用哪个类和方法。
回答by Nikolay Antipov
In your project you may have more than one main()
method. So, you should search it in files. Just find main which is declared as public static void
.
在您的项目中,您可能有不止一种main()
方法。所以,你应该在文件中搜索它。只需找到声明为的 main public static void
。
If you use an ECLIPSE you can try to search with special ECLIPSE search features (menu Search -> Java...).
如果您使用 ECLIPSE,您可以尝试使用特殊的 ECLIPSE 搜索功能(菜单搜索 -> Java...)进行搜索。
回答by Jlearner
Under eclipse Package Explorer right click on project name -> Run As -> Java Application
Eclipse will automatically search and execute main method i.e. public static void main(String[] args) {...}
在 eclipse Package Explorer 下右键项目名称 -> Run As -> Java Application Eclipse 会自动搜索并执行 main 方法即 public static void main(String[] args) {...}
回答by SteeveDroz
You better know where it is, because with Java, you can have several main()
for one project.
您最好知道它在哪里,因为使用 Java,main()
一个项目可以有多个。
I sometimes have one that runs the project as an application (standalone) and another that runs it as an applet.
我有时有一个将项目作为应用程序(独立)运行,另一个将它作为小程序运行。
The best practice is: know where it is, put it in an obvious place (like in the Main.java
file).
最佳做法是:知道它在哪里,把它放在一个明显的地方(比如在Main.java
文件中)。
回答by Neda
In IntelliJ IDEA, you can easily open the project then, there is a search icon in the upper right hand corner, you can easily search main and find out which java files of the project includes main, and also in the left panel where the project is opened you can see that (if you go through clusters) those java files which include main are indicated by a green run (arrow) icon near the java class icon. Good luck!!
在IntelliJ IDEA中,可以很方便的打开项目,右上角有个搜索图标,可以方便的搜索main,找出项目的哪些java文件包含main,也可以在左侧面板中找到项目所在打开后,您可以看到(如果您通过集群)那些包含 main 的 java 文件由 java 类图标附近的绿色运行(箭头)图标指示。祝你好运!!