Cannot cast eclipse project to IJavaProject

前端 未结 1 558
抹茶落季
抹茶落季 2021-01-17 23:07

I have the following code

    IJavaProject targetProject = null;
    IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
    for (IProject projec         


        
相关标签:
1条回答
  • 2021-01-17 23:39

    The code in your answer shouldn't work (typo?). Here is how you can create an IJavaProject:

    import org.eclipse.jdt.core.JavaCore
    ...
        if (project.hasNature(JavaCore.NATURE_ID)) {
            targetProject = JavaCore.create(project);
        }
    

    IProject is a type in the Eclipse Resources API and IJavaProject is a type in the Eclipse Java Model. They are not the same abstractions, but all IJavaProjects have an IProject.

    0 讨论(0)
提交回复
热议问题