How to get java main class from jar file

2020-08-26 10:51发布

问题:

I have an executable jar and i want to know the name of java main class from this jar

My question are if there is a java cmd to get this from jar metadata ?

回答1:

You can use unix command : unzip -p XXX.jar META-INF/MANIFEST.MF

or you can use jar commad jar tf XXX.jar and see the content of MANIFEST.MF.



回答2:

Technically a jar file can contain more than one main class.

When java executes a jar file, it looks in the META-INF/MANIFEST.MF file inside the jar to find the entrypoint.

There is no direct command to get this information, but you can unpack the jar (it's just a zip file) and look into the manifest yourself.

More about the manifest: https://docs.oracle.com/javase/tutorial/deployment/jar/defman.html

More about application entrypoints: https://docs.oracle.com/javase/tutorial/deployment/jar/appman.html