谢谢
解决方案如果 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类型?
发布评论