Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call java class method from jar (not main)

Tags:

java

jar

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

like image 464
Yermek Makulbek Avatar asked Mar 28 '26 12:03

Yermek Makulbek


1 Answers

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
like image 89
Thilo Avatar answered Mar 30 '26 02:03

Thilo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!