redzedi
redzedi

Reputation: 1995

Executing a class in remote jvm

I have a small test class that I want to run on a particular jvm that's already up and running (basically it's an web application running on Tomcat) . The reason I want to do this is I want to execute a small test class (with the main method and all) within that jvm so that I get the same environment (loaded and initialized classes) for my test class.

Is it possible to indicate that ,say through a jvm parameter, that it should not initialize a new vm to execute my class but instead go and execute on the remote vm and show me the result here, on my console. So the local jvm acts as a kind of thin proxy ?

I am not aware in case there are some tools that should make this possible .Also heard somewhere that java 6 jvm comes with an option like this , is that true ? Please help me.

Thanks,

Upvotes: 2

Views: 3873

Answers (5)

ruediste
ruediste

Reputation: 2949

After reading this question and the answers, I decided to roll my own little utility: remoteJunit

It is lightweight and dynamically loads classes from the client to the server JVM. It uses HTTP for communication.

Upvotes: 2

mhaller
mhaller

Reputation: 14232

I assume "small test class" is basically some debugging code you want to run to monitor your real application, which is deployed remotely on a Tomcat. If this is the case, you should connect your Eclipse debugger remotely to the Tomcat instance, so you can set a breakpoint at interesting locations and then use the Display view of Eclipse to run any arbitrary code you might need to perform advanced debugging code. As java supports Hot Code Replacement using the debug mechanism, you can also change existing code on the remote side with new code at runtime.

Upvotes: 0

HMM
HMM

Reputation: 3013

You might want to take a look at btrace. It allows you to run code in an already started JVM provided you don't change the state of the variables inside that JVM. With this kind of tracing, you might be able solve your problem in a different way. Not by running extra code in form of a new class but by adding safe code to and existing class running inside a JVM.

For instance, you might System.out.println the name of the file when there is a call to File.exists.

Upvotes: 1

Reginaldo
Reginaldo

Reputation: 907

RMI would also do the magic.

http://java.sun.com/javase/6/docs/technotes/guides/rmi/index.html

Make your web application start an RMI registry and register your service beans there.

Then in other JVM you can run a program that queries the RMI registry started by your web application for the services you want to verify and you are done.

Upvotes: 0

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147154

You might find JMX useful. Register an MBean in the server process. Invoke it with visualvm (or jconsole). (tutorial) Never tried it myself, mind.

Upvotes: 0

Related Questions