Which way is the best to go for building a webapp as osgi bundle via maven and start them with webstart? - osgi

I am looking for a way to reach my vision. What is the best way to go?
Here is my vision:
I would like to build a captain casa app via maven (as a war file).
Then i would like to create a osgi bundle from the builded war via maven.
Next i would like build a artifact which could be downloaded and started via java webstart (jnlp).
The jnlp file should be download the osgi environment with web container support (maybe jetty osgi service), next download osgi bundled war. Then the osgi container and the jetty service should be started and my war should be deployed. Finally the app is running local in a osgi environment.
There are many questions to be answered:
How can i build a captain casa app via maven to a war?
Which maven plugin should be used to build the osgi bundle (pax, maven-bundle-plugin, tycho, ...) What are the differnce?
How to build a jnlp artifact via maven which can deployed on a site?
How must be modified the osgi bundle to support java webstart?
Known informations:
Blog entry to prepare osgi bundle for java webstart.
many pages to maven plugins, such as pax, maven-bundle-plugin, tycho, bnd, ...

It might be worth asking this as 3 separate questions, but when building Web application Bundles I use the maven-bundle-plugin version 2.2.0 (currently unreleased, so you'll need to depend on a snapshot).
Then I use the following file structure:
src/main/java - any .java files
src/main/resources - any non .java files that should be on the classpath
src/main/webapp - static content, images, html files jsps and so on
Then inside the pom once you have configured the normal data for the maven-bundle-plugin you specify the following:
<_wab>src/main/webapp</_wab>
this will cause the static content to be pulled into the bundle and the bundle to be structured with the classes and resources in the WEB-INF/classes directory.

Related

Package and deploy OSGi bundles and Karaf features in Karaf Container

Recently, I have been working on Apache Karaf project.
The first one is a CXF REST service example and the second one is an Apache Karaf Maven example to run and deploy a Karaf container.
What I would like to do is to combine these two. The idea is to download a couple of JAR files from a repository and then package them into a Karaf.
Building Karaf Assembly manually then deploying the created JAR files in my deploy folder under Karaf is not a good idea if the task is reccurent each day. I would very much like to automate this if possible?
To achieve automatic deploy of Java project in Karaf, follow these steps:
Create a feature project: It is a Maven project and its goal is to create a descriptor of JAR (bundles) to be deployed under Karaf. The packaging of this Maven project is feature.
For your project of Karaf Assembly, add your feature as dependency and add it as boot feature so it can be installed when Karaf is up.
Look at this project https://github.com/benson-basis/karaf-feature-version-tc.
It has all the necessary configuration to automate Karaf building and deploy.

Why third party dependency is required exclusively from OSGi container even if I have it in my maven dependencies?

I want to know why OSGi do not respect the maven dependenceis.
I want to create one app in OSGi(AEM). I want to communicate(CRUD) to the database with the help of JPA(eclipselink).
I created maven project with aem-archetype.
Added all required dependencies(of JPA) into my maven project's pom file.
No errors in Eclipse, I built the project via mvn clean install and installed it into AEM(CQ5) via mvn sling:install. All good till now. No Errors.
But when I go and see my bundle in the felix console, I see that it is not Active but in Installed state.The error reported is that it could not resolve the javax.persistence package.
I was puzzled, I searched and I read about it here -
You have to make sure that you place the same version in another
bundle and deploy first. https://forums.adobe.com/thread/2325007
I converted JPA jar to OSGi bundle and installed in my OSGi container, and the error was gone. Great!
But why OSGi is not watching out for the dependencies I wrote in pom.xml of my maven project. Why it needs JPA strictly from OSGi bundle?
Maybe this is due to any architectural benefit, but could anyone please explain me here about this behaviour of OSGi? And why/how this feature of OSGi is useful ?
The <dependency> section of your Maven POM only covers your compile time dependencies. That means when you run Maven to build your project those dependencies are used to compile the source code and build your bundle. Maven itself is not aware of AEM or OSGi or any other platform or framework (e.g. Spring).
Maven just compiles your code.
You, as a developer, are responsible that all those required compile time dependencies are also available at runtime.
What we usually do is to create an AEM content package Maven module and put all of our required third party dependencies (e.g. JPA bundles) into it. This content package is then deployed by Maven so that those dependencies are also available at runtime.
Reason is: what you are adding as dependency is getting added in build path of your project and being available for your classes.When you run mvn install,it checks presence of all dependency and creates a bundle/jar for you.By default this bundle has only your project classes not other dependencies.
You need to check in depfinder whether external dependencies are already there in OSGi container,if not you have to load them in OSGi container either by embedding external dependencies in your bundle with the help of maven-bundle-plugin present in pom.xml or by making a bundle of jar file(I wont recommend that)which you have done.
I hope this helps!

Where to put configuration in a bndtools/maven project?

I have project where I use the bnd-maven-plugin from the bndtools project. I've tried to follow the conventions from the enRoute OSGI maven tutorial. So, I have a parent directory with a module pom, and a subdirectory for each bundle, and one for packaging and running the whole thing (with the bndrun file).
Question is, how do I pass configuration? Previously, when I built the bundles with the (felix) maven-bundle-plugin, I would drop the bundles in the deploy folder in Karaf, and make a file for the PID in the config directory, but I can't do that when building a standalone jar - or at least I can't find a way to do it.
Configuration is independent from bndtools and bnd-maven-plugin.
The way to provide configuration depends on the installed configuration admin impl. If you install felix config admin and fileinstall then you can supply the configuration in a config folder like you are used to.
For an example see the osgi-chat example. It is built with maven, the bundles are created with bnd-maven-plugin and the runnable jar is created using bndtools.
Felix config admin and file install are configured in rsa.bndrun.

Maven simple archetype for ejb (without web app and servlets)

I am looking for a simple archetype for EJB with working example.
I want build a single EAR file with pure EJBs (Servlet and WebApp are not required)
I have used this maven-archetype-j2ee-simple archetype and deleted servlets and projects primary-source and src folders.
I am able to build, but I am not able to deploy in to GlassFish, when I run the command mvn glassfish:deploy it is always looking for .war file inside the target folder.

OSGi bundle repository with plain Maven JARs

I am working on to reach a solution to deploy a web application as a bundle to Virgo 3.0.1.RELEASE. My scenario is:
I use Maven Bundle Plugin to generate the manifest.
I exclude all the JAR dependencies using Maven WAR plugin.
I need to command Virgo to host the plain Maven JAR artifacts in the local repository. As an instance Apache Karaf along with PAX can provide plain JAR files as OSGi bundles.
So,
Any ideas on how to configure Virgo for to host Maven repository plain JARs?
Generally, in your experience, what is the best solution to use a ready Maven repository and host it as an OBR?
Thanks in advance.
The best solution I've found so far is actually using Wrap Deployer on Apache Karaf.
Basically stick with Karaf, since it provides all you need :)
With Karaf and the features you don't really need a OBR, since the features service does a pretty good job of resolving already deployed bundles and won't install those again. You need to add the OBR flag to your features file though.

Resources