如何将字符串转换为IJavaProject类型?

编程入门 行业动态 更新时间:2024-10-26 02:32:50
本文介绍了如何将字符串转换为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类型?

本文发布于:2023-11-17 06:45:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1609193.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   转换为   如何将   类型   IJavaProject

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!