简体   繁体   English

在应用程序之间共享Java对象

[英]sharing java objects between applications

I want to write an application that when deployed on a server discovers some classes on that server and their methods and exposé a list of it to a client (via web service, servlet or RMI). 我想编写一个应用程序,当该应用程序部署在服务器上时,它会发现该服务器上的某些类及其方法,并将其列表公开给客户端(通过Web服务,Servlet或RMI)。

the client can then choose a method and activate it (with reflection). 然后,客户可以选择一种方法并激活它(使用反射)。

Problem is that my application is not in the same context of the other applications on the server so I can't activate their methods (I don't have access to their classloader). 问题是我的应用程序与服务器上其他应用程序不在同一个上下文中,因此我无法激活它们的方法(我无法访问其类加载器)。

I have a few ideas but not sure if they are feasible: 我有一些想法,但不确定它们是否可行:

  1. Create a jar and make all applications on the server know it (via Manifes file or by putting it in the server lib) - Problem is ,that way I can't exposé an interface to the client (maybe I can through RMI?) 创建一个jar并使服务器上的所有应用程序都知道(通过Manifes文件或通过将其放入服务器库中)-问题是,这样我就无法向客户端公开接口(也许可以通过RMI吗?)

  2. Create a WAR and link all applications to this WAR, so when they startup they load it (like linking to a jar) - as far as I know its not possible. 据我所知,创建一个WAR并将所有应用程序链接到该WAR,以便它们在启动时加载它(例如链接到jar)。

  3. Is there a classloader that knows all classes? 是否有一个知道所有类的类加载器? is there a way to get it? 有办法吗?

  4. How does profilers do it? 分析器是如何做到的?

Any idea will be welcomed. 任何想法都将受到欢迎。

3) AFAIK application servers generally have a class loader hierarchy and thus there's no single class loader that has access to all classes. 3)AFAIK应用服务器通常具有类加载器层次结构,因此没有单个类加载器可以访问所有类。 In fact, you often need to load multiple instances of the same class, eg when deploying independent applications that use static class variables or different versions of a class or a library. 实际上,您经常需要加载同一类的多个实例,例如,在部署使用静态类变量或类或库的不同版本的独立应用程序时。 Here's a short description of how JBoss does it. 这是JBoss如何做到简短描述。

4) Most likely profilers use the JVMTI . 4)最有可能的探查器使用JVMTI

However, you should keep in mind that it is not advisable to expose every class and every object due to security, stability and performance reasons. 但是,请记住,由于安全性,稳定性和性能原因,建议不要公开每个类和每个对象。 Should the user be able to invoke methods on internal classes or basic classes like String ? 用户是否应该能够在内部类或基本类(如String上调用方法? Should the user be able to call System.exit() ? 用户应该可以调用System.exit()吗? I'd say no, and thus you need to define some method of determining what to expose. 我会说不,因此您需要定义一些确定要公开内容的方法。 Most likely a much simpler solution (dedicated services) would meet your use case requirements (you didn't state them so that's just a guess). 最简单的解决方案(专用服务)很可能会满足您的用例需求(您没有声明它们,所以只是一个猜测)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM