javafx下启动spoon和carte

import javafx.application.Application;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

import java.io.File;

public class PDIStarter extends Application {

@Override

public void start(Stage primaryStage) {

Button startCarteBtn = new Button("启动 Carte 服务");

Button startSpoonBtn = new Button("启动 Spoon");

Button stopAllBtn = new Button("停止所有服务");

startCarteBtn.setOnAction(e -> startCarte());

startSpoonBtn.setOnAction(e -> startSpoon());

stopAllBtn.setOnAction(e -> stopAllServices());

VBox root = new VBox(10, startCarteBtn, startSpoonBtn, stopAllBtn);

Scene scene = new Scene(root, 300, 200);

primaryStage.setTitle("PDI 服务控制器");

primaryStage.setScene(scene);

primaryStage.show();

}

private void startCarte() {

try {

// 设置编码环境变量

ProcessBuilder pb = new ProcessBuilder(

"cmd.exe", "/c",

"chcp", "65001", "&&",

"set", "JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8", "&&",

"set", "KETTLE_NATIVE=Y", "&&",

"cd", "/d", "D:\\dev_install\\pdi-ce-9.4.0.0-343\\data-integration", "&&",

"start", "carte.bat", "127.0.0.1", "8819"

);

pb.start();

System.out.println("Carte 服务启动中...");

} catch (Exception e) {

e.printStackTrace();

}

}

private void startSpoon() {

try {

ProcessBuilder pb = new ProcessBuilder(

"cmd.exe", "/c",

"chcp", "65001", "&&",

"set", "JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF-8", "&&",

"set", "KETTLE_NATIVE=Y", "&&",

"cd", "/d", "D:\\dev_install\\pdi-ce-9.4.0.0-343\\data-integration", "&&",

"start", "spoon.bat"

);

pb.start();

System.out.println("Spoon 启动中...");

} catch (Exception e) {

e.printStackTrace();

}

}

private void stopAllServices() {

try {

ProcessBuilder pb = new ProcessBuilder(

"cmd.exe", "/c",

"taskkill", "/f", "/im", "java.exe",

"&&", "taskkill", "/f", "/im", "spoon.bat"

);

pb.start();

System.out.println("已停止所有服务");

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

launch(args);

}

}

相关推荐
camellias_3 小时前
【无标题】
java·tomcat
咸鱼2.03 小时前
【java入门到放弃】需要背诵
java·开发语言
椰猫子3 小时前
Java:异常(exception)
java·开发语言
win x4 小时前
Redis 使用~如何在Java中连接使用redis
java·数据库·redis
星晨雪海4 小时前
基于 @Resource 的支付 Service 多实现类完整示例
java·开发语言
阿维的博客日记4 小时前
什么是逃逸分析
java·juc
Ricky_Theseus5 小时前
C++右值引用
java·开发语言·c++
Rick19935 小时前
Java内存参数解析
java·开发语言·jvm
我是大猴子5 小时前
Spring代理类为何依赖注入失效?
java·后端·spring
勿忘,瞬间5 小时前
多线程之进阶修炼
java·开发语言