0

我创建了一个包装器JavaLaunchDelegate并创建了一个新的ZLaunchConfigurationDelegate扩展 this 。在这个包装器中,我尝试Launch使用Launch.terminate有时它无法终止先前的运行来终止。

Java 代码:

public static ILaunch getLaunchObject(String launchName) {
    ILaunch launchObj = null;
    ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
    ILaunch[] launches = launchManager.getLaunches();
    for(int i=0 ; i<launches.length ; i++) {
        ILaunch launch = launches[i];
        ILaunchConfiguration config = launch.getLaunchConfiguration();
        if(config != null) {
            String configName = config.getName();
            if(configName.equals(serviceName)) {
                launchObj = launch;
                break;
            }
        }

    }
    return launchObj;
}

public static void terminateLaunch(String launchName){
    ILaunch launch = getLaunchObject(launchName);
    if(launch != null){
        launch.terminate();
    }
}

terminateLaunch("mylaunch");

launch.terminate如果不起作用,我想强制终止该进程。

目标

如果我从 Eclipse 启动对象中获得了进程 ID。我将使用 os 命令终止该进程。

有什么方法可以从启动对象中获取进程 ID?

谢谢你 ,

坎南

4

1 回答 1

0

首先尝试终止所有进程和调试目标(如果此 Launch 处于调试模式)并终止 Launch。

private void terminate(ILaunch launch){
    try{
        IProcess [] processList = launch.getProcesses();
        for(IProcess process : processList) {
            if( ! process.isTerminated() ) {
                process.terminate();                    
            }               
            launch.removeProcess(process);
        }

        IDebugTarget [] debugTargetList = 
            launch.getDebugTargets();
        for(IDebugTarget debugTarget : debugTargetList) {
            launch.removeDebugTarget(debugTarget);
        } 

        launch.terminate();

    }catch(Exception ex) {
       // Exception
    }
 }
于 2013-01-10T09:35:46.543 回答