如何使用插件获取eclipse中项目文件的绝对路径

use*_*079 6 java eclipse-api eclipse-plugin

我正在尝试创建一个插件,它会给我一个在eclipse中打开的项目中所有文件的绝对路径列表.

我试过但我只能得到活动窗口的路径..

我的行动代码是:

  IWorkbenchPart workbenchPart = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart(); 
    IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor().getEditorInput().getAdapter(IFile.class);
    if (file == null)
        try {
            throw new FileNotFoundException();
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    String path = file.getRawLocation().toOSString();
    System.out.println("path: " + path);
Run Code Online (Sandbox Code Playgroud)

这里我只获取活动窗口的路径.但是我想要项目中所有文件的绝对路径列表..主要是src文件夹下的文件...

如果我能以同样的方式做到这一点,请指导我,还是需要使用一些不同的API.

Pra*_*mha 7

经过我的研究,我发现下面的代码将获得Eclipse当前工作空间项目目录的路径:

//get object which represents the workspace  
IWorkspace workspace = ResourcesPlugin.getWorkspace();  

//get location of workspace (java.io.File)  
File workspaceDirectory = workspace.getRoot().getLocation().toFile()
Run Code Online (Sandbox Code Playgroud)

注意:您需要导入org.eclipse.core.resourcesorg.eclipse.core.runtime使用这些API

资源