How to programmatically find a java file in eclipse from full classname?(如何以编程方式从完整的类名中找到 eclipse 中的 java 文件?)
问题描述
在 Eclipse 插件中,我想在编辑器中打开一个文件.我知道完整的包和类名,如何从中确定java文件的路径?
Inside an eclipse plugin, I'd like to open a file in editor. I know the full package and class name, how can I determine the path of the java file from this?
推荐答案
看看IJavaProject.findType(name)
方法.一旦有了 IType
,就可以使用 getPath() 或 getResource() 方法来定位文件.此方法搜索整个项目以及该项目中可见的所有内容.要搜索整个工作区,请遍历工作区中的所有 Java 项目,依次调用每个项目的 findType() 方法.
Take a look at IJavaProject.findType( name )
method. Once you have an IType
, you can use getPath() or getResource() methods to locate the file. This method searches across a project and everything visible from that project. To search the whole workspace, iterate through all the Java projects in the workspace, calling the findType() method on each in turn.
这篇关于如何以编程方式从完整的类名中找到 eclipse 中的 java 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何以编程方式从完整的类名中找到 eclipse 中的 java 文件?


基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 大摇大摆的枚举 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- Java Swing计时器未清除 2022-01-01
- 多个组件的复杂布局 2022-01-01