Reflection: take values from an unknown running alpplication

Posted by Dr.Lesh on Stack Overflow See other posts from Stack Overflow or by Dr.Lesh
Published on 2010-12-23T09:48:09Z Indexed on 2010/12/23 14:54 UTC
Read the original article Hit count: 234

Filed under:
|
|
|

I'm writing an application that searchs for Semaphore types in the fields of unknown classes in unknown application (passed by user). I made it using Reflection and it worked.

Now I want to fill up these semaphores with values, taking them from a running instance of this unknown application. So i took the class with "main" method of this unknown application, made a newInstance, and passed it when invoking the main method to start the application:

Class mainClass = getItSomeWhere();
Object instance = mainClass.newInstance();
Method mainMethod = mainClass.getDeclaredMethod("main", new Class[]{String[].class});
mainMethod.invoke(instance, new Object[]{args});

and it worked fine.

Now, how can I get the semaphore values, taking them from the classes of this running application, when I only have an instance of the main class?

Many thanks for the answers.

© Stack Overflow or respective owner

Related posts about java

Related posts about reflection