从终端调用Java方法 [英] calling java methods from a terminal

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

问题描述

假设我有一个Java程序 myProgram.jar ,该程序已在服务器上运行.要启动程序,我将其输入终端:

Suppose I have a java program, myProgram.jar, which I have running on a server. To start the program I would type this into the terminal:

>java -jar myProgram.jar

,该程序将继续无限期运行.现在,如果程序具有诸如

and the program would continue to run indefinitely. Now what about if the program had a function such as

void processInput(String text){
     //process the text
}

,我想通过SSH进入服务器并使用特定字符串调用此函数?因此我可以随时登录服务器并更改程序状态.这可能吗?

and I wanted to SSH into the server and call this function with a particular string? so I could log into my server at any time and alter the state of my program. Is this possible?

推荐答案

可以做到,但不容易.

有一些实现您可能想要的标准方法:MBean.看看 http://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html

There are standard ways to achieve what you probably want: MBeans. Take a look at http://docs.oracle.com/javase/tutorial/jmx/mbeans/standard.html

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

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