Eclipse,JDT:在类路径上查找一个知道其完全限定名称的文件

发布于 2024-10-08 07:50:48 字数 216 浏览 0 评论 0原文

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

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

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

Given the name ch/mollusca/sample/snippet.xml, is there an easy way to get a hold of this file in JDT code, when it is located in the projects classpath either as a source file or inside a JAR?

The file may also be inside another project, that is referenced by the one, where I'm trying to get a hold of the actual file behind the name.

This is specific to Java projects, so it's possible to get a hold of the IJavaProject if that helps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱本泡沫多脆弱 2024-10-15 07:50:48

这可能不是您想要的答案,但这是我能做的最好的答案(由于您的问题已经有 2 天的时间,我可能会向您抛出这个):

Eclipse 角文章:抽象语法树

Eclipse JDT - 抽象语法树 (AST) 和 Java 模型 - 教程

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

This is probably not the answer you want, but it's the best I can do (and since your question already has 2 days, I might has well throw you this):

Eclipse Corner Articles: Abstract Syntax Tree

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

These two great articles will point you to the right direction.

无远思近则忧 2024-10-15 07:50:48

这个怎么样:

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
    }
}

How about this:

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
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文