Getting runtime class information from the web? Something like javap but at runtime on class loaded in memory

StackOverflow https://stackoverflow.com/questions/1396449

  •  22-09-2019
  •  | 
  •  

Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top