Eclipse plugin code to create an IProject at a specified location

IProgressMonitor progressMonitor = new NullProgressMonitor();

IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
IProject project = root.getProject(page1.getProjectName());

I use this code to create a project in the workspace.

Now I want to create a project in the specified location, other than the workspace.

Can anyone give any suggestions?

+3
source share
1 answer

Finally, I found the code to indicate the location of the project to be created. This can be done using the setLocation () method of the IProjectDescription class as follows:

IProgressMonitor progressMonitor = new NullProgressMonitor();
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();


IProject project = root.getProject(page1.getProjectName());
    IWorkspace w = ResourcesPlugin.getWorkspace();
    IProjectDescription desc=w.newProjectDescription(project.getName()); 
    String projectLocation=page1.getProjectLocation();
    IPath path1=new Path(projectLocation+"/"+page1.getProjectName());
    desc.setLocation(path1); 
    project.create(desc, progressMonitor); 
    project.open(progressMonitor);
+3
source

All Articles