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

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

问题描述

我可以从命令行调用main(String[])以外的Java方法吗?

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

推荐答案

如果您为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目录的位置添加到路径中,您就可以开始了.您可以将jars放到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(String [])以外的Java方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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