Reputation: 2052
I have an application like the follows,
public class OpenApp {
public static void main(String[] args) {
if(args.length>0)
System.out.println("Hi " + args[0]);
System.in.read();
}
public static String sayHi(){
return "Hi";
}
}
So The OpenApp will be running. I have some other methods. Can I call the sayHi method from another application, without creating new instance of the class.? Because I have some data constrains on running OpenApp.
Please Correct me If my question is wrong. Simply I'm trying to communicate between 2 JVM. So, I read, RMI is the best way to make the communication. So Is there any other way.
Upvotes: 1
Views: 592
Reputation: 62797
For two applications to communicate, you need some form of Inter-Process Communication, IPC, pretty much by definition. So you need some kind of protocol. So, short answer to your question is: RMI is not the only way, but all other ways are similar, communication and not direct method call.
If you just want to call the method in code of another application, then add the .jar with the class to your application, or load the .jar at runtime, and (since that is a static method) just call the method. But this is just normal static method call, so you probably did not mean this?
Upvotes: 1