开发者

How to call a remote jar?

开发者 https://www.devze.com 2023-03-31 01:59 出处:网络
A newbie to Java, so please excuse my wording. Currently, on one server, I have a java wrapper around a 3rd party jar file.I am using: Class lc = Class.forName(\"pkg.lib\") to initialize the class.

A newbie to Java, so please excuse my wording.

Currently, on one server, I have a java wrapper around a 3rd party jar file. I am using: Class lc = Class.forName("pkg.lib") to initialize the class.

I need to put this 3rd party jar on a separate server. How can my java application on Server 1 call the 3rd party jar on Server 2?

Thanks开发者_如何学Python,


There are a number of approaches you might try:

  1. Implement a web-service API on Server 2, such that the code on Server 1 can call some URL on Server 2 which will trigger it to invoke your third-party JAR and then return the result (as JSON, or XML, or a serialized Object format, or what have you).

  2. You can use JMX/RMI to perform a remote method invocation and get a serialized copy of the result sent back to you.

  3. You can use JMS to dispatch a message from Server 1 to Server 2, and have a listener on Server 2 that receives the message and dispatches a result message back to Server 1.

  4. Or if you feel like a challenge, you can implement your own custom communication protocol to be used between Server 1 and Server 2, and make it do whatever you want. You might arrive at something similar to RTMP, which supports bidirectional remote-procedure invocations.


You can use Java RMI or maybe use web services to publish some of your functionality on server 2 and consume that web service from server 1. If you can give an example of your use case we can try to improve the solution even more in case this one already does not give any hints.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号