Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get java main class from jar file

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 ?

like image 575
Yaz Avatar asked Jul 02 '16 21:07

Yaz


People also ask

How do I find the main class of a jar file?

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.

How do I extract a class from a jar file?

You can open the jar file with winrar, this will show all the class files within, from there, you can drag them all into JD-GUI and decompile them all.

Can we get Java code from jar file?

Hi, Jar files are archive files that contains of a lot of different java classes (files). You can use winzip/winrar to open the jar files and you can see those java classes in jar files. Typically you can use a Java decompiler to decompile the class file and look into the source code.


2 Answers

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.

like image 149
sauumum Avatar answered Oct 10 '22 05:10

sauumum


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

like image 39
larsgrefer Avatar answered Oct 10 '22 05:10

larsgrefer