如何将字符串转换为IJavaProject类型? [英] how to convert string to IJavaProject type?

查看:161
本文介绍了如何将字符串转换为IJavaProject类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个插件。在此我将项目作为一个字符串的文本框输入,但是在继续之前必须将其转换为IJavaProject类型。我如何做?



谢谢

解决方案

如果 projectName 不存在,只是一个句柄的 IProject 将为null。
IJavaProject 也将为null ...所以我不建议 beny23 解决方案



JavaCore.create(IProject)的javadoc表示,目前没有检查是否存在或这个项目的java性质。



请参阅这个线程从头开始以编程方式创建Java项目。提取

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

您可以检查是否实际创建了:

  IJavaProject.getUnderlyingResource()。exists(); 

另请参见这个线程作为Java项目创建的另一个代码示例。



那个线程也创建项目,即使它们的性质比Java更完整。


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 before 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.

这篇关于如何将字符串转换为IJavaProject类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆