简体   繁体   中英

Eclipse Extension Point for Updating the Classpath

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

Roostergx provides part of the answer (ie, 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 technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM