Eclipse 插件开发中常用方法总结(不断更新...)

1.获取或者新建一个IProject

    public IProject createOrGetProject(String projectName){
    	
    	IProject project=ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
    	if(project.exists()){
    		return project;
    	}else{
    		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
			IWorkspace workspace = root.getWorkspace();
			NullProgressMonitor monitor = new NullProgressMonitor();	

			IProjectDescription description = workspace.newProjectDescription(projectName);
			try {
				project.create(description, monitor);
				project.open(IResource.BACKGROUND_REFRESH, new SubProgressMonitor(
						monitor, 500));
			} catch (CoreException e) {
				e.printStackTrace();
			}
			return project;
    	}

		
    }


你可能感兴趣的:(Eclipse 插件开发中常用方法总结(不断更新...))