Executing a different Jar file from another java program

后端 未结 2 1239
感情败类
感情败类 2020-12-20 10:41

As a part of my program, I have a connections manager that receives a connection from a client, and then gives the client a port number and a password to use to connect. A

2条回答
  •  生来不讨喜
    2020-12-20 11:04

    Include jar in the classpath and call the main method of the Main-class of the jar from your main.

    Suppose Main-class of CytoscapeInterface.jar is JarMain.class (You can look it up in META-INF of CytoscapeInterface.jar), then from your program, call it like this:

    JarMain.main(new String[]{"arg1", "arg2"});
    

    You can also call it from a new Thread so that you can continue with your program.

            new Thread(
            new Runnable() {
                public void run() {
                    try {
                        JarMain.main(new String[]{"arg1", "arg2"});
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }).start();
    

提交回复
热议问题