You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

通过Java ProcessBuilder启动后,自定义Eclipse插件工作集创建异常

问题:Eclipse插件创建工作集时停滞

我正在开发一个Java自动安装程序,负责配置Java、Maven、Eclipse及环境变量,启动带有自研插件的Eclipse后,插件会自动克隆、导入项目并执行mvn install,最后创建工作集。目前遇到的问题是:创建59个工作集到第37个时程序完全停滞,只能关闭启动Eclipse的Java应用才能恢复,找不到故障原因。

程序和插件仅通过conf.xml关联,该文件由Java应用写入、Eclipse插件读取,且创建工作集前已完成整个XML文件的解析,因此可以排除XML解析导致的问题。

启动Eclipse的代码

String[] command = { eclipseExePath, "-data", workspacePath };
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.environment().put(installation.javaName + "_HOME", javaPath);
try {
   Process process = processBuilder.start();
   process.waitFor();
} catch (IOException e) {
   e.printStackTrace();
}

创建工作集的代码

for (Map.Entry<String, List<String>> entry : workingSetMap.entrySet())
{
   if (monitor.isCanceled())
   {
      break;
   }
   String workingSetName = entry.getKey();
   List<String> keywords = entry.getValue();

   // 查找同名的已存在工作集
   IWorkingSet existingWorkingSet = workingSetManager.getWorkingSet(workingSetName);

   // 创建新工作集或复用已有工作集
   IWorkingSet workingSet;
   if (existingWorkingSet == null)
   {
      workingSet = workingSetManager.createWorkingSet(workingSetName, new IAdaptable[0]);
   }
   else
   {
      workingSet = existingWorkingSet;
   }

   // 根据关键词将项目加入工作集
   for (IProject project : allProjects)
   {
      if (monitor.isCanceled())
      {
         break;
      }
      monitor.subTask(project.getName());
      try
      {
         if (project.isOpen())
         {
            for (String keyword : keywords)
            {
               if (containsKeyword(project, keyword))
               {
                  System.out.println(keyword + " : " + project.getProject().getName());
                  workingSetManager.addToWorkingSets(project, new IWorkingSet[]
                  { workingSet });
                  break;
               }
            }
         }
      }
      catch (CoreException e)
      {
         e.printStackTrace();
      }
      monitor.worked(1);
   }

   // 将新工作集添加到管理器
   if (existingWorkingSet == null)
   {
      workingSetManager.addWorkingSet(workingSet);
   }

}

逻辑说明

遍历所有项目,若项目名称包含对应工作集关联的关键词,就将该项目加入工作集。


内容的提问来源于stack exchange,提问作者Dave

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 13:42:52