如何从JVM外部调用对象中的方法? [英] How can I call a method in an object from outside the JVM?

查看:165
本文介绍了如何从JVM外部调用对象中的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的Java类,可以使用输入验证有效地修饰Map,使用明显的void set()和String get()方法。

I have a really simple Java class that effectively decorates a Map with input validation, with the obvious void set() and String get() methods.

I'我希望能够有效地调用这些方法并处理来自JVM外部的返回值和异常,但仍然在同一台机器上更新:我想到的调用者不是另一个JVM;谢谢@Dave Ray

I'd like to be able to effectively call those methods and handle return values and exceptions from outside the JVM, but still on the same machine Update: the caller I have in mind is not another JVM; thanks @Dave Ray

我的实施考虑是典型的


  • 性能

  • 易于实施和维护(简单?)

  • 可靠性

  • 灵活性(即我可以打电话吗?从远程机器等。)

  • performance
  • ease of implementation and maintenance (simplicity?)
  • reliability
  • flexibility (i.e. can I call from a remote machine, etc.)

有没有'正确的方法?'如果没有,我有什么选择,什么是每个人的利弊是什么?

Is there a 'right way?' If not, what are my options, and what are the pro/cons for each?

(人们已经完成并且可以提供真实的反馈意见很棒!)

(Stuff people have actually done and can provide real-life feedback on would be great!)

推荐答案

好的。这是另一个尝试,因为我知道客户端不是Java。由于您需要进程外访问以及可能的远程机器访问,因此我认为JNI不是您想要的,因为这是严格的进程(并且总是麻烦)。以下是一些其他选项:

Ok. Here's another try now that I know the client is not Java. Since you want out-of-process access and possibly remote machine access, I don't think JNI is what you want since that's strictly in-process (and a total hassle). Here are some other options:

原始套接字:只需在Java中设置一个侦听器套接字并接受连接。当您获得连接时,请阅读请求并发回响应。几乎每种语言都可以使用套接字,因此这是一个非常通用的解决方案。但是,您必须定义自己的编组方案,解析等。

Raw Sockets : just set up a listener socket in Java and accept connections. When you get a connection read the request and send back a response. Almost every language can use sockets so this is a pretty universal solution. However, you'll have to define your own marshalling scheme, parsing, etc.

XML-RPC :这些日子并不像时髦,但它简单而有效。 Java库以及大多数其他语言的库。

XML-RPC : this isn't as hip these days, but it's simple and effective. There are Java libraries as well as libraries in most other languages.

CORBA :如上所述,CORBA是一个选项,但它非常复杂,专家越来越难以接受。

CORBA : as mentioned above, CORBA is an option, but it's pretty complicated and experts are getting harder to come by.

Web服务器:在您的应用中设置嵌入式Web服务器并处理请求。我听说过有关 Jetty 的好消息,或者您可以使用一个提供Java 。我已经成功地使用后者通过用Java编写的模拟将KML文件服务到Google Earth。大多数其他语言都有用于发出HTTP请求的库。您如何对数据(XML,文本等)进行编码取决于您。

Web Server : set up an embedded web server in your app and handle reqests. I've heard good things about Jetty or you can use the one provided with Java. I've used the latter successfully to server KML files to Google Earth from a simulation written in Java. Most other languages have libraries for making HTTP requests. How you encode the data (XML, text, etc) is up to you.

Web服务:我认为这会更复杂,但您可以使用 JAX-WS 将对象公开为Web服务。 NetBeans有很好的工具来构建Web服务,但这可能有点过头了。

Web Services : This would be more complicated I think, but you could use JAX-WS to expose you objects as web services. NetBeans has pretty nice tools for building Web Services, but this may be overkill.

这篇关于如何从JVM外部调用对象中的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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