Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find main() function in a big project

Tags:

java

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 ?

like image 824
Adrian Avatar asked Jun 16 '11 07:06

Adrian


People also ask

How do you identify the main method?

main(): It is a default signature which is predefined in the JVM. It is called by JVM to execute a program line by line and end the execution after completion of this method. We can also overload the main() method. String args[]: The main() method also accepts some data from the user.

Where is the main method in Java project in Eclipse?

From the Eclipse IDE menu, select Search>Java ... . In the dialog, enter: "main" as the search string. "Method" in the "Search For" box.

Where is the main method in Visual Studio?

Go into the project properties by right clicking the project in the solution explorer and click properties. On the first tab you will see a drop down list for the entry point. Select the appropriate main method.

Who will call main method in Java?

When the Java interpreter executes an application (by being invoked upon the application's controlling class), it starts by calling the class's main method. The main method then calls all the other methods required to run your application.


2 Answers

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.

You need to find out what your server is, what technologies have been used in the java project and how it was setup.

like image 153
drekka Avatar answered Sep 24 '22 01:09

drekka


  1. Use eclipse's build in search function and search for "main(" in all projects java files (= entire workspace)
  2. Look for the application jar and look at it's manifest file, it may contain the name of the main class
  3. 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)
  4. 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.

BTW - If the big server project is a server based application, say the final build result is a war or an ear file, then the entry point doesn't have to be a static main method. Then it might not even have one single starting point.

like image 37
Andreas Dolk Avatar answered Sep 23 '22 01:09

Andreas Dolk