Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Run Another Java App in Current JVM

  Asked By: Fahimah    Date: Aug 25    Category: Java    Views: 943
  

I want to use another Java program from with in my java program... But i dont
want to use

Runtime.getRuntime().exec("java OtherApp");

because that runs the other app in seperate JVM... I want to run that in the
current jvm in another THREAD... can i do that... if yes then how ???

looking for your advise... (sami, u there?)

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Jim Williamson     Answered On: Aug 25

you can do this ..
call the main method of OtherApp.

ex : OtherApp.main(null); main method is static .. so it can be called like
this. you need to pass the String array as the argument or null if you are
neglecting the arguments. This will run  as a same thread.
If you want to run as another thread, create seperate thread  and call the main
method from within the run method of the thread.

Hope this answers you query.

 
Answer #2    Answered By: Sherri Parker     Answered On: Aug 25

use java.lang.reflect in a soket server that accepts main class definition from
a
port.

ex:
- u'll send "LOAD com.filika.project.runner.Runner" from soket to your server
program
- server program  'll find the main class and loads it to its vm that running
with the
help of reflect package.
- and also u can send more initial parameters with reflect ->more at:
java.sun.com

or u can define a generic interface like

public interface MyLoadable{
public void load() throws Exception;
public void start()throws Exception;
public void stop()throws Exception;
public void unload()throws Exception;

}

 
Answer #3    Answered By: Rachel Barnes     Answered On: Aug 25

I think you could write a little class, extended
from Thread, which will be responsible to call your
other application, like this

public class Caller extends Thread {
public void run() {
String[] parameters = new String[0];
OtherApp.main(parameters);
}
}

and then call it from your calling class:

new Caller().start();

Of course, the other app  must be in the main
application classpath. I think this shuld work

 
Didn't find what you were looking for? Find more on Run Another Java App in Current JVM Or get search suggestion and latest updates.




Tagged: