Skip to content
Advertisement

Call java class method from jar (not main)

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

Advertisement

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
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement