在运行时获取Maven的模块类路径

时间:2014-03-25 14:21:45

标签: java maven runtime classpath processbuilder

我想在不同的进程中运行java app,并使用另一个maven模块的classpath。我怎样才能做到这一点?我尝试那些东西:

String separator = System.getProperty("file.separator");
            String path = System.getProperty("java.home") + separator + "bin" + separator + "java";             

ProcessBuilder processBuilder = new ProcessBuilder(
              path,
              "-cp",
              //System.getProperty("java.class.path"),
              ".." + separator + nodeProperties.getClasspath(),
              nodeProperties.getMainClass());
            processBuilder.directory(new File(".." + separator + nodeProperties.getWorkingDir()));
            Map<String, String> env = processBuilder.environment();
            env.put("jmx-port", "8000");
            env.put("mode", "SUPER_PEER");
            processBuilder.inheritIO();
            try {
                Process process = processBuilder.start();
                process.waitFor();
            } catch (Exception e) {
                e.printStackTrace();
            }
            System.out.println("SuperPeer stopped");

0 个答案:

没有答案