用于更新类路径的 Eclipse 扩展点
问题
给定我作为插件/扩展编写的类路径容器,如何将其自动添加到类路径中?
背景
好吧,我是一名经验丰富的 Java 开发人员,但对于编写 Eclipse 插件却非常陌生。这几天我一直在谷歌搜索、遵循教程并阅读其他插件的源代码。我确切地知道我想做什么,但不知道如何去做。
现在,在 Eclipse 中,当我单击资源并选择“作为 JUnit 测试运行”时,如下所示:
在幕后,m2eclipse 插件以某种方式生成一个包含“Maven 依赖项”类路径容器的运行配置,如下所示:
我最好的猜测是“Maven 依赖项”类路径容器是通过某些扩展点添加的M2Eclipse 插件。同样,我想在用户运行 JUnit 测试时自动添加我的类路径容器,以便它显示在“用户条目”下。我可以使用什么扩展点来实现类似的事情?我一直在查看 org.eclipse.jdt.core.classpathContainerInitializer ,但我不确定这是否能满足我的需要。
Ideal Result
理想情况下,我想编写一个插件,获取项目构建路径中的每个条目并将其添加到运行配置的类路径中(每当通过以下方式创建新的启动配置时:Run As > JUnit test)。这应该是 Eclipse 的默认行为,但事实并非如此!
我的下一个最佳解决方案是简单地将自定义类路径容器自动添加到运行配置的构建路径中。归根结底,我只想要我们团队运行/启动的任何 java 代码都有一个类路径。这不应该那么难!
任何有关如何实现这一目标的建议将不胜感激!甚至还有关于在哪里查看以了解如何使用特定扩展点的基本指示(基本的 JavaDocs API 很糟糕)。谢谢,
- gMale
Question
Given a Classpath Container I've written as a plugin/extension, how do I add it to the classpath, automatically?
Background
Ok so I'm an experienced Java Developer but extremely new to writing Eclipse Plugins. I've been googling, following tutorials and reading source code of other plugins for a couple days. I know exactly what I want to do but not exactly how to do it.
Right now, in Eclipse, when I click a resource and choose "Run as JUnit test" as in:
Behind the scenes, the m2eclipse plugin somehow generates a run configuration that contains the "Maven Dependencies" classpath container, like the following:
My best guess is that the "Maven Dependencies" classpath container is added through some extension point being used by the M2Eclipse plugin. Similarly, I want to add my classpath container, automatically, whenever a user runs a JUnit test--so it shows up under "User Entries." What extension point(s) can I use to make something like that happen? I've been looking at org.eclipse.jdt.core.classpathContainerInitializer but I'm not sure that's going to do what I need.
Ideal Result
Ideally, I'd like to write a plugin that takes every entry in the project's build path and adds it to the classpath of a run configuration (whenever a new launch configuration is created via: Run As > JUnit test). This should be the default behavior of Eclipse but it's not!
My next-best solution would be to simply add my custom classpath container to the run configuration's build path, automatically. At the end of the day, I just want one classpath for any java code our team runs/launches. This shouldn't be so hard!
Any advise on how to achieve any of this would be appreciated! Even basic pointers on where to look to understand how particular Extension Points are intended to be used (the basic JavaDocs APIs are terrible). Thanks,
- gMale
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Roostergx 提供了部分答案(即如何创建类路径容器)。正如您所承认的,第二部分是如何自动添加它。
我建议使用名为 org.eclipse.ui.startup 的扩展点。这允许您贡献在 Eclipse 启动时(几乎)尽早运行的代码。每次启动时,您都可以迭代所有项目并查看是否有任何现有项目需要您创建的类路径容器。
Roostergx provides part of the answer (i.e., how to create the classpath container). The second part, as you admit, is how to add it automatically.
I would recommend using an extension point called org.eclipse.ui.startup. This allows you to contribute code that runs (pretty much) as early as possible when Eclipse starts up. On every startup, you can iterate through all projects and see if any existing projects require the classpath container that you created.
文章位于 http://www.ibm.com/ developerworks/opensource/tutorials/os-eclipse-classpath/index.html 为插件提供了精彩的描述和源代码,该插件定义了项目特定的类路径容器,其中包含指定目录中的所有 jar 文件。
The article at http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/index.html provides an exellent description and source for a plugin that defines a project specific classpath container that includes all the jar files in a specified directory.