Search code examples
javaeclipseeclipse-jdtabstract-syntax-tree

Eclipse JDT IJavaProject get root file


I have the below code fragment which returns the relevant IJavaProject from a CompiliationUnit:

IJavaProject project = compilationUnit.getJavaProject();

I need to find a file in the root of the project, but I can't figure out how to locate it. If I loop on project.getAllPackageFragmentRoots() I can see the src folder,the package below the src folder, and the standard JRE classes, but not my root file.

How can I load the a file under the root folder? (Preferably into a File object)


Solution

  • I found my solution:

        IJavaProject project = compilationUnit.getJavaProject();
    
        IProject p = project.getProject();
        IFile rm = p.getFile("file.xml");
    

    Simple really.