What allows Java to find out what the main class is in a .jar

3

As Java does to find out which is the main class in a file .jar

    
asked by anonymous 27.10.2015 / 15:54

2 answers

4

He does not find out.

The .jar usually includes a file named Manifest.mf that is inside the META-INF folder and contains a line indicating which is the executable class, similar to this:

Main-class: nome.do.pacote.ClasseExecutavel

As @Techies reported, it should contain this method:

public static void main(String [] args)

and should be in the nome/do/pacote/ClasseExecutavel.class folder.

(Taken from: link )

    
27.10.2015 / 17:21
1

When we develop a system in Java we have to have a starting point. Imagine a system where you have hundreds of classes and thousands and methods. Do we have to start from somewhere right?

That's why the JVM Java virtual machine will look for the MAIN method on your system.

In short, the main class is the one that contains this statement:

public static void main(String [] args)

Here has an article where you can perhaps better understand.

    
27.10.2015 / 17:09