Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » non-osgi jars: embedded in bundle or in plugin directory?
non-osgi jars: embedded in bundle or in plugin directory? [message #512165] Thu, 04 February 2010 09:33 Go to next message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
We created a core system which makes use of 74 external jar libraries which we want to use in Eclipse RCP. It is not GUI specific.

We would like to start with the "one big bundle" approach of getting this core system to work, instead of having to OSGi-ify our core system and find OSGi bundles for our dependencies. (Later we should probably remove unneeded external dependencies and OSGI-ify our own system)

We can use Maven (with the bundle plugin) to create an OSGi bundle.

I already have successfully done this, but when I tell it to unpack all external jars before creating the bundle, the bundle jar will be in a big mess: resource files for different specific jars get into the root directory of the bundle and for example many LICENSE.TXT files are dropped because there can be only one such file.

The other option is to embed the jars inside the bundle (jars within a jar), which gives a very clean bundle jar. (Disadvantage: not usable outside of OSGi). This also seems to work, until the code in our own Eclipse plugin explicitly need access to a class from an embedded jar. Although this class is exported by the bundle and the jar is on the bundle classpath, the Eclipse compiler tells it can not find the class! Shouldn't this be supported by OSGi?
Am I doing something wrong here, or is this the usual behavior?

The last and probably currently best approach I can think of is to create a bundle which does not contain the jars but uses a "lib" directory for the external jars. Is this an official OSGi way? Or would this automatically mean we have to turn it into an Eclipse Plugin which can only be used by Eclipse? In this case, do we need to have a plugin.xml file?

[Updated on: Thu, 04 February 2010 09:36]

Report message to a moderator

Re: non-osgi jars: embedded in bundle or in plugin directory? [message #512218 is a reply to message #512165] Thu, 04 February 2010 12:41 Go to previous messageGo to next message
Michael Golovanov is currently offline Michael GolovanovFriend
Messages: 37
Registered: October 2009
Member
Hi, guy

You are in a right way, but ...


Create bundle project, inside it create folder lib and import your non osgi jars. Than open bundle manifest and add jars to bundle class path (update class path need to be checked)

Regards, Mike
Re: non-osgi jars: embedded in bundle or in plugin directory? [message #512252 is a reply to message #512218] Thu, 04 February 2010 14:13 Go to previous messageGo to next message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
You are right, I can already do it using the PDE tools. I guess my question boils down to what would be the final structure when you export a bundle/plugin. I guess I could just use the export functionality and check this myself...

I would like to know this because there are a few disadvantages for us to your approach:


  • I don't want to manually adjust the project each time our core system dependencies change
  • other developers should be able to use the bundle and I really don't want to put the external libraries into source control so they can build it
  • in the end I want to automate the build using a combination of Maven and Buckminster


To solve the first 2 points I would like to build a complete bundle/plugin with Maven which can be used in Eclipse from a network folder/p2 update site.

[Updated on: Thu, 04 February 2010 14:14]

Report message to a moderator

Re: non-osgi jars: embedded in bundle or in plugin directory? [message #512267 is a reply to message #512252] Thu, 04 February 2010 14:26 Go to previous messageGo to next message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
Ok this is weird... Indeed I created a plugin project from existing jars and selected that it should be a general OSGi bundle. When I add this as a project dependency it compiles fine.

When I export it as a deployable bundle (making sure I deselect to unpack the jars) I get one jar which contains the external jars and a manifest and is a valid OSGi bundle without a plugin.xml, just like I can already make myself with Maven. When I add this jar to my target platform it does not compile. Just like happened when I made the bundle myself with Maven!
Re: non-osgi jars: embedded in bundle or in plugin directory? [message #512908 is a reply to message #512267] Mon, 08 February 2010 10:38 Go to previous messageGo to next message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
This is annoying!!!!! When I see the FindBugs plugin they have external libraries under a lib directory outside of the bundle jar and have their Bundle-ClassPath set to lib/librarya.jar, lib/libraryb.jar, etc...

So I made a "plugin from existing jars" project where I manually move my libraries to a lib directory and prepend them with "lib/" in my Bundle-ClassPath. Surely this is the same setup as in the FindBugs plugin?

Before this move it worked fine, but now it says that it cannot find my Export-Package packages!!!!!!!!!

Edit: you have to remove all jars from the build path of the bundle, and add them in again so the build path now points to the jars in the new lib location. Then it works!

[Updated on: Mon, 08 February 2010 13:52]

Report message to a moderator

Re: non-osgi jars: embedded in bundle or in plugin directory? [message #512991 is a reply to message #512908] Mon, 08 February 2010 14:05 Go to previous messageGo to next message
Henno Vermeulen is currently offline Henno VermeulenFriend
Messages: 126
Registered: July 2009
Senior Member
Ok, I finally also got Maven to build a pure OSGi bundle which embeds our external dependencies and which can be used as a compile time and runtime dependency for an Eclipse plugin.

The trick I did is to create a bundle with embedded jars in the usual way, but to unpack the bundle contents. I then manually copied these contents into a directory in a project in my workspace with the folder structure:

platformtarget/plugins/myartifactidandversion

where myartifactidandversion is the name of the jar with .jar removed.
So this directory now contains my lib directory with all the jars and a META-INF directory with manifest.mf.

I then added ${workspace_loc}/project_name/platformtarget to my platform target settings and Eclipse finds the bundle!

Now people who checkout the entire project from Subversion can use Maven to (re)build the bundle, copy the result to that directory and add the bundle to the target platform. (These last steps could still be automated.)

My bet is that after everything is compiled I can then use the bundle jar with embedded jars in the target platform, but Eclipse simply won't compile to a jar bundle.

Thanks a lot for all your help Twisted Evil .....
Re: non-osgi jars: embedded in bundle or in plugin directory? [message #713874 is a reply to message #512991] Tue, 09 August 2011 09:10 Go to previous messageGo to next message
dimo.velev is currently offline dimo.velevFriend
Messages: 13
Registered: August 2011
Junior Member
Thank you guys, you made my day!

I have spent hours trying to find out why my bundles, when deployed over P2, did not work in eclipse helios. That was the reason.
Re: non-osgi jars: embedded in bundle or in plugin directory? [message #1828515 is a reply to message #713874] Thu, 11 June 2020 08:41 Go to previous message
Jose Ramon Garcia is currently offline Jose Ramon GarciaFriend
Messages: 2
Registered: January 2019
Junior Member
I know this is an old post, but maybe I can help other people searching about this.

I need to "add" a plugin named B to a pre-existing plugin from a p2 repository named A. The A plugin looks for a license file that I want to put inside my B plugin, but A needs to have the license file in its classpath.

I cannot edit A plugin easily so I tried to add B as a fragment plugin, and it works ok. I can add my license file (or classes to be instantiated by class.forName, I suppose) to my B plugin, and it works like a charm.

About adding a lot of jars inside a plugin, take care about it because maybe it will take a lot of time to find classes inside this "jars-inside-jar" structure. If you use the profiler you can see the big time it uses unzipping jars.
Previous Topic:grid table Toolbar items not getting visible
Next Topic:License File
Goto Forum:
  


Current Time: Sat Nov 09 00:14:42 GMT 2024

Powered by FUDForum. Page generated in 0.03750 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top