开发者

how to convert string to IJavaProject type?

I am developing a plugin.In this i take project as input from textbox which is a string , but it has to be converted to IJavaProject type b开发者_Go百科efore proceeding. How can i do that ?

Thanks


If projectName does not exist, IProject, which is just a handle, will be null. IJavaProject will also be null... so I would not recommend beny23's solution.

The javadoc for JavaCore.create(IProject) states, "no check is done at this time on the existence or the java nature of this project".

See this thread for creating a Java Project programmatically from scratch. Extract

final IJavaProject javaProject = JavaCore.create(project);
final IProjectDescription projectDescription =
  workspace.newProjectDescription(projectName);
projectDescription.setLocation(null);
project.create(projectDescription, new SubProgressMonitor(progressMonitor, 1));

You can check if is has actually been created with:

IJavaProject.getUnderlyingResource().exists();

See also this thread as another code example of Java Project creation.

That thread also creates project, even though their nature is more complete than just Java.


The following should work

IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IJavaProject javaProject = JavaCore.create(project);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜