java代码启动服务

package com.example.dxw.apiController;

import java.io.IOException;

public class StartJar {
    public static void main(String[] args) {
        try {
            // 定义要执行的命令
//            String command = "java -jar \"D:\\path\\to\\your\\yourJarFile.jar\"";
            String command = "java -jar D:\\开机文件\\doc2-9201.jar";

            // 创建进程构建器
            ProcessBuilder builder = new ProcessBuilder(command.split("\\s+"));

            // 启动进程
            Process process = builder.start();

            // 等待进程退出
//            int exitCode = process.waitFor();

            // 打印进程退出码
//            System.out.println("Process exited with code: " + exitCode);
            System.out.println("项目启动成功!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

你可能感兴趣的:(java,python,pycharm)