Executing class in remote jvm
I have a small test class that I want to run on a specific jvm that is already up and running (it is basically a web application running on Tomcat). The reason I want to do this is to execute a small test class (with the main method and all) inside this jvm so that I get the same environment (loaded and initialized classes) for my test class.
Is it possible to specify that, say through the jvm parameter, it should not initialize a new vm to execute my class, but instead go in 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 don't know if there are some tools that should make this possible. Also heard that java 6 jvm comes with an option like this, is it true? Please help me.
Thank,
source to share
You might want to take a look at btrace . It allows you to run code in an already running JVM as long as you don't change the state of the variables inside that JVM. With this kind of tracing, you could solve your problem in a different way. Not by running additional code as a new class, but by adding safe code and an existing class running inside the JVM.
For example, you can System.out.println
specify a filename when called File.exists
.
source to share
After reading this question and answers, I decided to run my little utility: remoteJunit
Lightweight and dynamically loads classes from client to JVM server. It uses HTTP for communication.
source to share
You may find JMX useful. Register MBean
in the server process. Call it with visualvm
(or jconsole
). (tutorial) Never tried it myself, mind.
source to share
RMI will do magic as well.
http://java.sun.com/javase/6/docs/technotes/guides/rmi/index.html
Make your web application a runnable RMI registry and register your beans service there.
Then, in another JVM, you can run a program that queries the RMI registry from your web application for the services you want to test and you're done.
source to share
My guess is that the "little test class" is basically the debug code you want to run to control your real application that is being deployed remotely to Tomcat. If so, you should connect your Eclipse debugger remotely to your Tomcat instance so you can set a breakpoint at points of interest, and then use the Eclipse display view to run any arbitrary code you might need to run your extended debug code. Since java supports Hot Code replacement using the debug engine, you can also modify existing code on the remote side with new code at runtime.
source to share