简体   繁体   中英

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)

I found my solution:

    IJavaProject project = compilationUnit.getJavaProject();

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

Simple really.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM