以编程方式将现有项目导入Eclipse
问题内容:
我正在尝试导入项目以通过编程方式使其黯然失色。我不想使用UI模式。
以下是我用于导入项目的代码:
IProjectDescription description = ResourcesPlugin.getWorkspace().loadProjectDescription( new Path("PROJECT_PATH/.project"));
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(description.getName());
project.create(description, null);
project.open(null);
我只得到project文件夹以及.location file
,.markers.snap
文件和.syncinfo.snap
文件,但没有得到源文件夹等。
问题答案:
用 org.eclipse.ui.wizards.datatransfer.ImportOperation
尝试这样的事情:
IOverwriteQuery overwriteQuery = new IOverwriteQuery() {
public String queryOverwrite(String file) { return ALL; }
};
String baseDir = // location of files to import
ImportOperation importOperation = new ImportOperation(project.getFullPath(),
new File(baseDir), FileSystemStructureProvider.INSTANCE, overwriteQuery);
importOperation.setCreateContainerStructure(false);
importOperation.run(new NullProgressMonitor());