Recently i wanted to run a jar file where its Main entry is not specified in the MANIFEST file. I knew this can be done since i’ve done it before, but couldn’t remember how to do it. So as usual i googled it but could not find it.
The thing is that this is a scenario that can arise when there are multiple entry points (mutiple classes having static main methods) in the jar file.
Funny enough the solution was pretty simple. Eventhough one might think that you need to specify the extry point class and the jar file which it is contained, the truth is we look at that fact in a wrong angle. What we have to do is to specify the class name and then the class path which the jvm should look for relevant classes (thus our jar should be included in this path).
say we have a class foo.class (which has a static main method) and it is in the jar file bar.jar. Then to execute the jar using the static main method present in foo class
$ java -cp bar.jar foo
here the class name should be a fully qualified class name. You can add more paths to the -cp parameter seprating them from a “:”
Tags: Add new tag, cannot find entry point, main class not specified in manifest, multiple entry points in jar, multiple main classes in a jar file, multiple main methods in single jar, run a jar file, run custom class in jar file, run static main method in a jar, specify entry point in command line, specify main class in command line