I try to build a Eclipse plugin that has to use a self written jar which is dependent on other jars, but I don't get the point where to start with handling jars as seperate PlugIns. Anywhere I have to use just the .jar files or am I wrong?
Asked
Active
Viewed 4.5k times
3 Answers
76
I think I found a proper solution; the trick is that you have to implement all the files via Eclipse. I just copy here the solution which was posted to news.eclipse.platform:
Include the jars in a plugin:
- Use
Import
>File System
to import the jar files into your plugin project, say in the<project>/lib
directory. - Use
Add...
button to add the jars to the classpath section of theplugin.xml
>Runtime
tab. - Use
New...
button to add "." library back (with no quotes, of course). - Make sure your binary build exports the new jar files on the
plugin.xml
>Build
tab. - Save
- On the project, use
context menu
>PDE Tools
>Update Classpath
to correctly add the jars to the eclipse project classpath.

David Corral
- 4,085
- 3
- 26
- 34

ethnix
- 1,165
- 1
- 8
- 13
-
1What if I have two plugins that reference the same jar file...I do not want to add it twice? Can I export the package in one plugin and reference it in another? Would that be the correct way to do it? – nbz Jun 14 '12 at 13:24
-
Instead of importing the file with Eclipse, you can also create a symlink that points from the project folder to the file's location somewhere else. For example a symlink to the local Maven repository. – akuhn Sep 05 '13 at 01:21
2
What is a self-written jar?
Normally you turn 3rd party jars into bundles using an OSGi MANIFEST.MF (See New>Plug-in Development>Plug-in from Existing JAR archive) or you include them in your plugin.jar and add extra Bundle-ClassPath entries as mentioned by TomaC.
If you mean at runtime your plugin will create a new jar and needs to load it, that's different, though.

Paul Webster
- 10,614
- 1
- 25
- 32
-
this refers more precisely to a project which i exported as a runnabl jar; I also tried to use the "Plugin from Existing Jar archive"-wizard but it didn't work though. The process I want needs a xml parser e.g. and so on, if I press a button, a background process has to be called which calls a http request, parses it into xml and returns some values to the plugin – ethnix Apr 26 '11 at 08:15
-2
Project Properties -> Java Build Path -> Add External jars. Is this what you are looking for?

TomaC
- 89
- 6
-
Maybe try to wrap the .jar in a plugin and then just add that plugin as a dependencie. – TomaC Apr 21 '11 at 14:18
-
exactly this is the point, i don't get; how can i wrap the jar in a plugin when this jar depends on other ones... the create plugin from jar wizard in eclipse didn't work well,as i cant import the classes from my plugin although i see it in my dependencies – ethnix Apr 21 '11 at 14:27
-
2Try creating a new plug-in project. Then just copy/paste your jar file in the new project. Go to Runtime->Classpath add add the .jar. Build the project and then add it as a dependencie on your main plugin, see if you can import now. – TomaC Apr 21 '11 at 15:08
-
I copied the jars in the root of the plugin project folder, added them with their names in the classpath, but as i try to add it to my dependencies, I can't find them – ethnix Apr 21 '11 at 15:30
-
1I just created a small test wrapper plugin over jdom. Here is the code from the wrapper manifest.mf `Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: PluginWrapper Bundle-SymbolicName: PluginWrapper Bundle-Version: 1.0.0.qualifier Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ClassPath: jdom.jar1` . Using this wrapper I can import org.jdom packages in a test plugin. – TomaC Apr 21 '11 at 15:57
-
thank you for your help, that was exactly what I did; i copied the needed jars into the root folder of my plugin and added them as you did to my manifest.mf. However, for any reason I can't import org.dom4j for example, any further idea? thanks so far – ethnix Apr 26 '11 at 08:09
-
as i allready mentioned, you must not implement the jars via "add external jars" but via "filesystem" – ethnix Apr 26 '11 at 09:17
-
An important point is that you need to create a plugin project first (don't create a plugin from an existing jar). Then you can follow TomaC's steps. – MrMas Apr 05 '13 at 20:11