Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Eclipse插件开发:如何获取当前选定项目的路径?_Java_Eclipse_Eclipse Api - Fatal编程技术网

Java Eclipse插件开发:如何获取当前选定项目的路径?

Java Eclipse插件开发:如何获取当前选定项目的路径?,java,eclipse,eclipse-api,Java,Eclipse,Eclipse Api,我正在编写一个插件,它将解析项目中的一组文件。但目前我一直在通过EclipseAPI寻找答案 插件的工作原理是这样的:每当我打开一个源文件时,我都让插件解析源文件对应的构建文件(这可以通过缓存解析结果来进一步开发)。获取文件非常简单: public void showSelection(IWorkbenchPart sourcePart) { // Gets the currently selected file from the editor IFile file = (IFi

我正在编写一个插件,它将解析项目中的一组文件。但目前我一直在通过EclipseAPI寻找答案

插件的工作原理是这样的:每当我打开一个源文件时,我都让插件解析源文件对应的构建文件(这可以通过缓存解析结果来进一步开发)。获取文件非常简单:

public void showSelection(IWorkbenchPart sourcePart) {
    // Gets the currently selected file from the editor
    IFile file = (IFile) workbenchPart.getSite().getPage().getActiveEditor()
        .getEditorInput().getAdapter(IFile.class);
    if (file != null) {
        String path = file.getProjectRelativePath();
        /** Snipped out: Rip out the source path part
         * and replace with build path
         * Then parse it. */
    }
}

我的问题是我必须使用硬编码字符串作为源文件和构建文件的路径。有人知道如何从Eclipse检索构建路径吗?(顺便说一句,我在CDT工作)。还有一种简单的方法可以确定源文件的源路径是什么(例如,一个文件位于“src”目录下)?

您应该看看,尤其是GetOutpunterties和getAllSourceRoots操作。也有一些简单的例子。我和JDT一起工作,所以这就是我能做的。希望有帮助:)

教程链接似乎已断开:(教程的链接已断开