1

I am working with Websphere and complicated classloading issues. I want to be able to download or print information that would normally get printed by javap (the methods, etc).

I may also need to get the raw binary class data, to perform a binary diff.

How would you do this?

Berlin Brown
  • 11,504
  • 37
  • 135
  • 203
  • 1
    There are some built in classloader diagnostics, accessibly through the console. Were they any use? – djna Sep 08 '09 at 21:42
  • The reflection APIs (obj.getClass().getDeclaredMethods() and friends), should be able to get you most of what you want. – jsight Sep 08 '09 at 22:10

1 Answers1

1

You could write a Servlet or JMX MBean that exposes the class to the your client.

Servlet:

String resourceParameter = ...;
OutputStream out = ...:
InputStream input = Thread.currentThread().getContextClassLoader()
   .getResourceAsStream(resourceParameter)
write(input, out);

Client:

GET http://host/DiagnosticServlet?resource=your/ClassName.class

The resource parameter has to be your class file your.ClassName -> your/ClassName.class. You can then save the file and use javap.

(I think the MBean has to encode your class file into a string (e.g. Base 64) as byte[] is not supported. But I'm not sure about that. The rest would be the same.)

If this will be deployed in production some form of authentication should be configured.

Thomas Jung
  • 32,428
  • 9
  • 84
  • 114