通过下面的代码,我可以以编程方式创建eclipse项目,但我应该在创建之前检查项目是否存在,如果不存在,则应该创建它,否则,应该刷新它,任何提示都将受到欢迎!
IProjectDescription description = null;
IProject project = null;
description = ResourcesPlugin.getWorkspace().loadProjectDescription(
new Path(new File(projectfolder).getAbsolutePath()
+ "/.project"));
project = ResourcesPlugin.getWorkspace().getRoot()
.getProject(description.getName());
project.create(description, null);
//project.refreshLocal(IResource.DEPTH_INFINITE, new org.eclipse.core.runtime.NullProgressMonitor());
project.open(null);
答案 0 :(得分:2)
IProject
扩展IResource
,其方法为exists()
:
if (!project.exists()) {
project.create(description, null);
}