我有此代码:
ThreadPoolExecutor t;
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
System.out.println("root" + root.getLocation().toOSString());
Runnable runnable = new Runnable() {
public void run() {
try {
IPath projectDotProjectFile = new Path("C:\\Users\\rezbi\\eclipse-workspace\\AutoRefactor-master\\AutoRefactor-master" + "/.project");
IProjectDescription projectDescription = workspace.loadProjectDescription(projectDotProjectFile);
IProject project = workspace.getRoot().getProject(projectDescription.getName());
JavaCapabilityConfigurationPage.createProject(project, projectDescription.getLocationURI(), null);
//project.create(null);
} catch (CoreException e) {
e.printStackTrace();
}
}
};
// and now get the workbench to do the work
final IWorkbench workbench = PlatformUI.getWorkbench();
workbench.getDisplay().syncExec(runnable);
IProject[] projects = root.getProjects();
for(IProject project: projects){
System.out.println(project.getName());
}
我按照以下链接中的说明进行操作: http://techdc.blogspot.com/2015/01/eclipse-workbench-has-not-been-created.html
我仅添加了以下依赖项:
org.apache.felix.gogo.command
org.apache.felix.gogo.runtime
org.apache.felix.gogo.shell
org.eclipse.equinox.console
org.eclipse.osgi
不幸的是,它给了插件依赖关系您好-我运行该应用程序,得到了未解决的依赖关系,添加了依赖关系,还有更多未解决的依赖关系。而且,如果我从运行配置中选择“添加必需的软件包”,那么我会得到“尚未创建工作台。创建OSGi模块时出错”
那么有没有更简单的方法来解决这个问题?
更新: 我如何创建项目在这里: http://codeandme.blogspot.com/2012/02/creating-headless-application.html
这是一个插件项目。
要运行,我右键单击清单文件。选择运行方式,然后选择osgi框架。注意:我也尝试从运行配置中包括插件依赖项。然后,我尝试运行> Eclipse Application。无论哪种方式,我都会得到相同的结果:还没有创建工作台。
在同一个Java类中,以下代码有效:
public Object start(IApplicationContext context) throws Exception {
// TODO Auto-generated method stub
//String PACKAGE_NAME = "cucumber";
//final IPackageFragment packageFragment = JavaCoreHelper.getPackageFragment(PACKAGE_NAME);
//System.out.println(packageFragment);
//final ICompilationUnit cu = packageFragment.createCompilationUnit("Application5.java", "", true, null);
//IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
//IProject m_project = root.getProject("cucumber");
//System.out.println("m_project "+m_project);
IWorkspace workspace = ResourcesPlugin.getWorkspace();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
System.out.println("HELLO ");
IProject[] projects = root.getProjects();
for (IProject project : projects) {
try {
printProjectInfo(project);
} catch (CoreException e) {
e.printStackTrace();
}
}
// createAProject();
//System.out.println("test "+root.getProject(name));
return null;
}
但是,一旦我尝试访问工作台,事情就会中断。