Call java class method from jar (not main)

Tags: ,



Is this possible to call a specific method (other than main) of a class in a jar file from command line?

Answer

If you are talking about running Java code from the command-line, then no.

You can specify a class name, but not which method to call, that always has to be public static void main(String[] argv).

What you could do is write a helper class (or script like BeanShell) to do that.

java -cp theJar.jar;.  my.helper.WrapperClass theClassToCall theMethodtoCall arg1 arg2


Source: stackoverflow