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

查看:28
本文介绍了我可以从命令行调用 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天全站免登陆