我可以从命令行调用main()以外的java方法吗? [英] Can I invoke a java method other than main() from the command line?

查看:158
本文介绍了我可以从命令行调用main()以外的java方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以从命令行调用main()以外的java方法吗?

Can I invoke a java method other than main() from the command line?

谷歌对这些信息并不是很了解。

Google is not so forthcoming with this information.

谢谢

推荐答案

如果为JVM语言安装REPL (Groovy可能需要最少的工作才能开始),然后你可以在REPL提示符下调用Java方法(Groovy的名字叫做groovysh)。 groovysh 有一些奇怪的功能(我最不喜欢的是用 def 声明变量不能做你想做的事情认为它应该)但它仍然非常有用。这是一个有趣的功能,Groovy不尊重隐私,因此您可以调用私有方法并检查私有变量的内容。

If you install a REPL for a JVM language (Groovy probably takes the least work to get started with), then you can invoke Java methods at the REPL prompt (Groovy's is called groovysh). groovysh has some odd features (my least favorite bit is that declaring variables with def doesn't do what you'd think it should) but it's still really useful. It's an interesting feature that Groovy doesn't respect privacy, so you can call private methods and check the contents of private variables.

Groovy安装包括groovysh。下载zip文件,将其解压缩到某处,将bin目录的位置添加到路径中,然后就可以了。您可以将jar放入lib文件夹,对于您正在运行的代码和该代码使用的库,Groovy会在那里找到它们。

Groovy installs include groovysh. Download the zip file, extract it somewhere, add the location of the bin directory to the path and you're good to go. You can drop jars into the lib folder, for the code you're running and libraries used by that code, and Groovy will find them there.

这篇关于我可以从命令行调用main()以外的java方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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