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

Asked

Viewed 1,093 times

3

How Java Does to Figure Out Which Main Class in a File .jar

  • I think these answers may be peculiar to you: http://answall.com/questions/4964/comor-executar-jar-com-o-prompt

2 answers

4

He doesn’t find out.

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

Main-class: nome.do.pacote.ClasseExecutavel

As @Techies reported, it should contain this method:

public static void main(String [] args)

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

(Drawn from: /a/4995/357)

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. We have to start from somewhere right?

That’s why the JVM(Java virtual machine) will look for the method MAIN in your system.

Briefly, the main class is that which contains that instruction:

public static void main(String [] args)

Here has an article where perhaps Voce can better understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.