0

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).

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?)

  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.

  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.

Tomer
  • 17,787
  • 15
  • 78
  • 137
  • 3
    You should tell us what you want to achieve with this, because obviously, exposing any method of any class (which instance) doesn't make much sense. What's your end goal? A web service is accessible... from the web, and thus doesn't even need to be invoked from a Java program. – JB Nizet Nov 30 '11 at 13:29
  • Suffice to say that I have an idea and I need this functionality. I know a web service is accessible through the web, I'm talking about exposing POJO functionality. – Tomer Nov 30 '11 at 14:29
  • Your requirements don't make sense. Please explain us how you plan to allow a client calling this method: http://docs.oracle.com/javase/6/docs/api/java/awt/CardLayout.html#maximumLayoutSize%28java.awt.Container%29 or this one: http://docs.oracle.com/javase/6/docs/api/java/sql/ResultSet.html#getAsciiStream%28java.lang.String%29. If you don't want to ask a clear question, we won't be able to give you a clear answer. – JB Nizet Nov 30 '11 at 14:36
  • OK, i'll try to be clearer. I'm only going to exposé some methods that make sense (Business logic sense) to the client and not any arbitrary method of any arbitrary object. I'm sorry i can't say more but it's an idea i have for a startup and naturally I can't exposé to much. – Tomer Nov 30 '11 at 15:06

1 Answers1

0

3) AFAIK application servers generally have a class loader hierarchy and thus there's no single class loader that has access to all classes. In fact, you often need to load multiple instances of the same class, e.g. 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.

4) Most likely profilers use the 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? Should the user be able to call 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).

Thomas
  • 87,414
  • 12
  • 119
  • 157
  • I've edited my question a bit so it'll be more clear (i hope :) ) . I intend to exposé only some objects with Business meaning. What i need is exactly what I described in the question: Exposé some Objects that live on a server to an external client that will be able to activate them. The more i think of it the more i like the idea of RMI. – Tomer Nov 30 '11 at 14:32