Programmatically importing an existing project into Eclipse

前端 未结 4 1088
时光说笑
时光说笑 2020-12-14 03:55

I am trying to importing the project to eclipse through programmatically. I dont want to use UI mode.

Below is the code I used for importing the project:

<         


        
相关标签:
4条回答
  • 2020-12-14 04:16

    Use org.eclipse.ui.wizards.datatransfer.ImportOperation

    Try something like this:

    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());
    
    0 讨论(0)
  • 2020-12-14 04:18

    You're probably missing a line with

    description.setLocation(new Path("/absolute/path/to/project/folder"));
    
    0 讨论(0)
  • 2020-12-14 04:19

    I was able to use the following code to set focus to a newly imported project:

    IProjectDescription description = ResourcesPlugin
      .getWorkspace()
      .loadProjectDescription(new Path("PROJECT_PATH/.project"));
    
    description.setLocation(new Path("/absolute/path/to/project/folder"));
    
    IProject project = ResourcesPlugin
      .getWorkspace()
      .getRoot()
      .getProject(description.getName());
    
    project.create(description, null);
    project.open(null);
    
    0 讨论(0)
  • 2020-12-14 04:33

    Your code seems to be fine. What do you exactly mean by you couldn't get the source folder? Have you tried to refresh the project?

    project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());

    0 讨论(0)
提交回复
热议问题