Adding jars to a Eclipse PlugIn
Asked Answered
H

3

30

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?

Hester answered 21/4, 2011 at 13:6 Comment(1)
This is the right answer - How to add EXTERNAL jarsSwimming
H
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:


  1. Use Import > File System to import the jar files into your plugin project, say in the <project>/lib directory.
  2. Use Add... button to add the jars to the classpath section of the plugin.xml > Runtime tab.
  3. Use New... button to add "." library back (with no quotes, of course).
  4. Make sure your binary build exports the new jar files on the plugin.xml > Build tab.
  5. Save
  6. On the project, use context menu > PDE Tools > Update Classpath to correctly add the jars to the eclipse project classpath.
Hester answered 26/4, 2011 at 9:16 Comment(2)
What 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?Aerobiosis
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.Quarta
S
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.

Shizukoshizuoka answered 21/4, 2011 at 18:8 Comment(1)
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 pluginHester
U
-2

Project Properties -> Java Build Path -> Add External jars. Is this what you are looking for?

Underexposure answered 21/4, 2011 at 13:35 Comment(8)
Maybe try to wrap the .jar in a plugin and then just add that plugin as a dependencie.Underexposure
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 dependenciesHester
Try 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.Underexposure
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 themHester
I 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.Underexposure
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 farHester
as i allready mentioned, you must not implement the jars via "add external jars" but via "filesystem"Hester
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.Vanderbilt

© 2022 - 2024 — McMap. All rights reserved.