从jar(不是main)调用Java类方法 [英] Call java class method from jar (not main)

查看:85
本文介绍了从jar(不是main)调用Java类方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过命令行在jar文件中调用类的特定方法(不是main)?

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

推荐答案

如果您正在谈论从命令行运行Java代码,则不会.

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

您可以指定一个类名,但不能指定要调用的方法,该类名必须始终为public static void main(String[] argv).

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

您可以做的是编写一个帮助程序类(或诸如BeanShell之类的脚本)来完成该操作.

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

这篇关于从jar(不是main)调用Java类方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆