用于更新类路径的 Eclipse 扩展点

发布于 2024-09-29 15:16:26 字数 1137 浏览 5 评论 0原文

问题

给定我作为插件/扩展编写的类路径容器,如何将其自动添加到类路径中?

背景

好吧,我是一名经验丰富的 Java 开发人员,但对于编写 Eclipse 插件却非常陌生。这几天我一直在谷歌搜索、遵循教程并阅读其他插件的源代码。我确切地知道我想做什么,但不知道如何去做。

现在,在 Eclipse 中,当我单击资源并选择“作为 JUnit 测试运行”时,如下所示:


for some reason, my pics don't work anymore. I'll fix this soon...


在幕后,m2eclipse 插件以某种方式生成一个包含“Maven 依赖项”类路径容器的运行配置,如下所示:

alt text

我最好的猜测是“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:


for some reason, my pics don't work anymore. I'll fix this soon...


Behind the scenes, the m2eclipse plugin somehow generates a run configuration that contains the "Maven Dependencies" classpath container, like the following:

alt text

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 技术交流群。

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

发布评论

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

评论(2

沧笙踏歌 2024-10-06 15:16:26

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.

强者自强 2024-10-06 15:16:26

文章位于 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.

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