如何有效地终止ILaunch对象?

时间:2013-01-10 06:36:05

标签: eclipse eclipse-plugin

我在JavaLaunchDelegate上创建了一个包装器,并创建了一个新的ZLaunchConfigurationDelegate来扩展它。在这个包装器中,我尝试使用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?

谢谢,

卡纳安

1 个答案:

答案 0 :(得分:0)

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

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
    }
 }