Is there a place where I can download Java EE API JARs as OSGi bundles?
I don't know of anywhere where you can do that, but you can wrap the jars and deploy them as bundles with the wrap scheme.
So the command that you would want to use to pull them from maven and wrap them as bundles would be osgi:install -s wrap:mvn:javax/javaee-api/6.0.
Apache Geronimo produces API jars for the Java EE packages and they are all (at least all the ones I've used) OSGi bundles. They are all installed in maven central. You can search for them in maven central here and either download them for use outside maven, or you can add the dependency to your pom and get them that way.
Related
I got a 3rd party jar which I am using for Blowfish decryption in a bundle that I need to deploy on apache karaf.
So now I also need karaf to know this jar but every solution I find is about creating a whole bundle for that jar which is pretty much for a simple library imo.
What I already did is installing that jar in my local maven repository and adding the dependency but this also doesn't work (at least on karaf).
Is there any other way to get 3rd party jars on apache karaf to work?
Are you using a features xml file? If so you could use wrap:mvn: to make it available:
<feature name="feature1" version="1.0.0">
<bundle>wrap:mvn:group.id/third.party.artefact.id/version</bundle>
<bundle>mvn:group.id/your.artefact/version</bundle>
</feature>
This will bundle the third party jar at runtime and make sure it's installed for your bundle to use. Taken from Karaf - Creating bundles
In addiction to #fiw you may want to osgify your thirdparty jar using Bndtools. In order to achive it:
Download bnd tools
Open a shell where you have downloaded bnd-2.4.0.jar.
Type:
java -jar bnd-2.4.0.jar wrap -o osgify-dependency.jar dependency.jar
where dependency.jar is your third party and osgify-dependency.jar will be the output.
Deploy to maven repo overriding the previous maven coordinates, or deploy your thirdparty with different coordinates.
mvn deploy:deploy-file -Dfile osgify-dependency.jar ...
I am running Apache servicemix 4.5.2. I want to install a feature, i.e. a jar file.
The feature I wanted is jtidy.
The pom dependence is:
<dependency>
<groupId>jtidy</groupId>
<artifactId>jtidy</artifactId>
<version>4aug2000r7-dev</version>
</dependency>
and the repository is
http://repo1.maven.org/maven2/jtidy/jtidy/4aug2000r7-dev/jtidy-4aug2000r7-dev.jar
I know the command features:install webconsole, for example but jtidy is not in my features:list. I've also tried using the addurl command but it didn't work.
(addurl mvn:http://repo1.maven.org/maven2/jtidy/jtidy/4aug2000r7-dev)
The Karaf documentation recommends to add a feature descriptor using the Features XML schema but unfortunately the link is broken.
Up to know what i did is to download the jtidy.jar and copied it to my deploy directory. It works, but I don't think that this is the correct way.
Do anybody knows how to install jtidy in servicemix correctly?
Thanks!
There's difference between installing a feature and installing a single JAR or OSGi bundle.
A feature is defined in an XML file. A feature consists of a number of bundles, configs, ... that are installed together. Have a look at http://karaf.apache.org/manual/latest-2.3.x/users-guide/provisioning.html to learn more about features in Karaf.
In this case, you want to install a single JAR into the container. You can use the command osgi:install to do this, followed by a URL pointing to the JAR (e.g. mvn:jtidy/jtidy/4aug2000r7-dev).
However, in your case, there's one more complexity. jtidy is not an OSGi bundle by itself. The easiest way to add the necessary OSGi metadata, would be to use the wrap: protocol to automatically add the OSGi metadata to the JAR.
So, to wrap things up - to install this jtidy dependency in Apache ServiceMix, you can use
osgi:install wrap:mvn:jtidy/jtidy/4aug2000r7-dev
I'm new in OSGI development and am struggling to understand how best to handle dependent JARs.
i.e. if I'm creating a bundle the likelihood is that I will need to use a few 3rd party JARs. When I create my bundle JAR to deploy to OSGI, obviously these 3rd party JARs are not included and thus the bundle will not run.
I understand that one option is to turn these JARs into bundles and deploy them to the OSGI container. When I bundled and try deploy third party jar it throws error for their own dependent jars and these dependencies are endless and not possible to fulfill.
What is the best solution to this?
-- Anurag
Finally I resolve third party jar issue actually I forger to add following tag in my POM.xml file
<_exportcontents>*
My issue is resolve, thanks to all of you for your support and giving me valuable clues.
If you are a beginner with osgi then I would not recommend to bundle bigger libs yourself. Often more than defining some import and export headers is required and it can become very difficult. Fortunately a lot of libs are available as bundles.
If the original lobs is not yet a bundle then you can search in maven central for a bundled version from servicemix bundles.
Using apache karaf is also often a big help. There are karaf features with predefined deps for a lot of libs like activemq, cxf, camel, openjpa, ...
In the worst case you can embed the lib and all deps in your own jar. This tends to cause class loading issues though if you try to share some classes between bundles.
What lib is the problem in your case?
A lot of libraries you mention (log4j, quartz, dom4j) have already been converted to OSGi bundles by Springsource. You can find them in the Springsource Enterprise Bundle Repository. All Hibernate libraries > 4.2 are also osgified.
You have three choices:
Find the library in some pre-made bundles (Springsource Repository, Eclipse Orbit Repository, etc.)
Include the libraries into your bundle as an external library (Make a directory lib, copy your jar files there, and reference them from the Bundle-Classpath element in MANIFEST.MF)
Convert the library into an OSGi bundle (e.g. with the bnd wrapconverter, example here)
I want to develop a multi-module application according to OSGi specification. Let's assume that one of my modules uses Apache Commons Logging 1.1.1. Spring provides a bundled version of Apache Commons Logging 1.1.1 in their repository, so I can add the corresponding dependency in my POM.
If I install my bundle in Apache Felix for example, is it right that the dependency to Apache Commons Logging 1.1.1 will not be resolved until I install the bundle of Apache Commons Logging 1.1.1 as well? My bundle will try to import a package that hasn't been exported.
I don't really understand how dependency management works in the OSGi world. Should I install every bundle that my application needs? Also, I don't understand how it integrates with Maven?
Thanks in advance for your explanations
EDIT: I've seen there is a subproject of Apache Felix called OBR that seems to facilitate bundles management (e.g. deployment). But, we already have a Maven architecture with local repositories, private repositories... How is OBR integrated to Maven?
If you want to use OSGi together with maven then I recommend Apache Karaf as a server which can use the Felix OSGi framework. The advantage is that you can install bundles directly from maven repositories using mvn: urls.
If you just use Apache Karaf with a maven repo then you have no transitive resolution at runtime. You have to install all bundles you need. What helps a lot is that karaf has the concept of features. So you can use the features as coarse grained building blocks. You can also create your own features where you refer to other features and bundles. This allows to install your whole app with one command.
Felix and Karaf also support OBR but you would have to create your own OBR Repo. There are currently no public OBR repos. The advantage of OBR is that it can resolve most of the transitive dependencies. The Karaf features even work together with OBR so you can just list some top level bundles in the feature and let OBR resolve the rest.
In practice I have good experiences with simple Karaf features without OBR. It is some manual work but less than you would expect and works quite well.
OSGi dependencies are based on Java packages: when a bundle states that it needs to import a given package (indicating a range of versions that are acceptable), the framework will attempt to "wire" that import to a suitable version of that package, that must be exported by another bundle.
If the package cannot be found, the bundle won't be resolved and cannot be started - so yes you'll need to install all bundles that your application requires, and as Christian indicates there are various tools that can help you with that.
A simple way to get the required bundles is to use the maven-dependencies-plugin to grab the bundles from Maven's list of dependencies and copy them somewhere where your app can find them at startup to install them, as done in [2] (in launcher/pom.xml), a small example app that I wrote.
You could also use Sling's maven-launchpad-plugin [3] to generate a runnable jar file that embeds the OSGi framework and all bundles that you need, and sets up everything at startup.
About the import and exports - without going into details, assuming you use the maven-bundle-plugin [1] to build your bundles, you'll specify what packages you want your bundle to export (others will be invisible to other bundles), and the maven-bundle-plugin will generate (in most cases automatically, but you can override that as needed) the list of packages to import, so there's usually not much work if your own code is cleanly split between packages that you want to export and internal implementation packages.
[1] http://felix.apache.org/site/apache-felix-maven-bundle-plugin-bnd.html
[2] https://github.com/bdelacretaz/OSGi-for-mere-mortals
[3] http://sling.apache.org/site/maven-launchpad-plugin.html
I have a java project that compiles down to an OSGi bundle. I'm using the maven-bundle-plugin to create the bundle, and the maven-sling-plugin to push the bundle to my running OSGi server. At the moment, my project has two dependencies (Guava and Gson) that need to be manually installed in the Felix server prior to installing the bundle. The manual install for these two dependency bundles only needs to occur once (when first setting up the OSGi server), but since it's a manual process, I'd kind of like to just push it into the "mvn install" phase.
I've looked at a number of maven plugins (maven-sling-plugin, maven-ipojo-plugin, dependency plugins, etc.), but I'm afraid that I just don't have enough knowledge to know where to start, or even to search in Stackoverflow for the solution (I have a suspicion that this has already been answered).
So - is there a clean way to install/start dependent bundles with maven? Something where I can specify a jar and a runlevel, and have the installation take place prior to my bundle being installed?
The Ops4j pax construct project might help: http://team.ops4j.org/wiki/display/paxconstruct/Pax+Construct
Looks like it's possible to use maven to specify which bundles to install and then spin up a felix osgi environment as described here:
http://www.sonatype.com/books/mcookbook/reference/ch01s04.html