【问题标题】:Eclipse, JDT: Find a file on the classpath knowing its fully qualified nameEclipse,JDT:在知道其完全限定名称的类路径上查找文件
【发布时间】:2010-12-20 15:28:37
【问题描述】:

鉴于名称 ch/mollusca/sample/snippet.xml,当它作为源文件或 JAR 位于项目类路径中时,是否有一种简单的方法可以在 JDT 代码中获取该文件?

该文件也可能在另一个项目中,由该项目引用,我试图在其中获取名称后面的实际文件。

这是特定于 Java 项目的,因此如果有帮助,可以获取 IJavaProject。

【问题讨论】:

    标签: eclipse eclipse-pde eclipse-jdt


    【解决方案1】:

    这可能不是你想要的答案,但这是我能做的最好的(因为你的问题已经有 2 天了,我可能会把这个扔给你):

    Eclipse Corner Articles: Abstract Syntax Tree

    Eclipse JDT - Abstract Syntax Tree (AST) and the Java Model - Tutorial

    这两篇很棒的文章将为您指明正确的方向。

    【讨论】:

      【解决方案2】:

      这个怎么样:

      IEditorPart activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
      if ( activeEditor != null ) {
          IResource activeEditorResource = (IResource)activeEditor.getEditorInput().getAdapter( IResource.class );
          if ( activeEditorResource != null && activeEditorResource.getFullPath() != null ) {
              String activeFileName = activeEditorResource.getFullPath().toOSString();
              //...do something with the active file
          }
      }
      

      【讨论】:

        猜你喜欢
        • 2010-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-29
        • 2018-03-20
        • 2015-02-23
        • 1970-01-01
        相关资源
        最近更新 更多