Calling a class from another program in which they are in different places

I have two programs, and I have to call a program that is in a different place, that is, the talking caller is in d: // start and is called a program in f: // call. How to do this in java?

Can I use this method to implement in the calling program?

try { Process p = Runtime.getRuntime().exec( new String[] {"cmd.exe", "/c", "F:/call.java"}); InputStream in = p.getInputStream(); OutputStream out = p.outputStream(); } catch (IOException e) { e.printStackTrace(); } 
+4
source share
1 answer

You can run another Java program using the exec command, for example:

 Runtime.getRuntime().exec("java /directory/com/Main.java") Runtime.getRuntime().exec("java -cp /directory/package.jar com.Main") 

If you need to call methods in this class within the same JVM, you can try loading the jar at run time and then calling the classes reflexively.

+2
source

All Articles