Search code examples
javanetbeansprogram-entry-point

is it good to have multiple main() in your application java


i heard that java doesn't care about how many main() method you have in your application.. but what main() method will be called if you have multiple when you build your app in jar file and is it good to have multiple main()?


Solution

  • You would have to declare it in the manifest file which indicates which is your Main class.

    Have a look at https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html

    Example:

    Manifest-Version: 1.0

    Created-By: 1.7.0_06 (Oracle Corporation)

    Main-Class: MyPackage.MyClass