Where to put configuration in a bndtools/maven project? - maven

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.

Related

Eclipse: How to include dependencies in osgi bundle export?

Using Eclipse, I have a (sort of) working OSGI bundle. It uses Maven to pull a lot of dependencies.
If I do right-click > Run As "Maven Build" and select the "package" as the goal, I end up with a jar with all my dependencies (good), but if I do "Export > OSGI Bundle" the dependencies are missing.
The issue is that I have another project (WebSphere Liberty Feature Project) that includes the bundle, but when it pulls it, it is also missing dependencies, so the resulting .esa file also misses the dependencies.
Is there a way to have eclipse process the dependencies so I don't have to manually package it outside eclipse or write a maven project exclusively for the purpose?
Thank you!
I was having the same issue when I came across your post.
I assumed that the jars would be included in the exported jar and be found at runtime.
Originally, I had created a seperate "lib" directory and added the libraries to it, but they would not be included when exporting either as Bundle export or Liberty feature export (ESA)
I solved the problem first be using the "Java Archive into OSGi Bundle" import wizard.
You can select a jar dependency and add it to you bundle of your choice with the wizard. What I noticed when I used this, is that the jars were added to the "BundleContent" folder in the chosen bundle.
As I had a number of libraries to include, I simply moved them all to the "BundleContent" folder, updated the build time and runtime classpaths and then when exporting, the dependencies were all included and at runtime, the classes could then be found when they previously were not.
In your POM, have you used maven-bundle-plugin and its usage-details for creating a bundle. If not, you can use it to define creation of your bundle and can also define dependencies to be embedded when the bundle is created.

opendaylight: difference between features/features-X and features/odl-X

I am developing an application for nitrogen. When I ran maven to generate an archetype, I got directories like features/features-X and features/odl-X with pom.xml in each one. Presumably, I am supposed to put feature dependencies in these pom.xml files. What is the difference between these two directories? Thanks
The features-X directory aggregates all the project's features in a feature repository. The odl-* directories are the project's single features. A feature repository is registered with karaf via the feature:repo-add command or the featuresRepositories property in etc/org.apache.karaf.features.cfg. It makes all the project's features available to karaf so they can be installed via feature:install.

How do I deploy a maven created webapp to tomcat

So I was following http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ for a simple tutorial on how to use maven and jsf. I created a maven project by running mvn archetype:generate -Dfilter=org.apache:maven-archetype-webapp in my command prompt. Then I continued with the tutorial, I wound up creating all necessary files, but then when I got to the end, I realized I did have a server created. So I created one real quick, but when it came to the point of adding files to the server (from the add or remove dialog box), no projects or files showed up. I am not on my computer where the project is located so I can't copy/paste the .pom file in, but it looks practically exactly like the pom in the tutorial (only difference is groupId, artifact, ect.) No additional plugins, dependencies, or configs.
Do you want to deploy the webapp within Eclipse to Tomcat? Or as some sort of automatic/continuous deployment?
Within Eclipse you often need to add the Dynamic Web project and JSF facets to your project so Eclipse recognizes the project as deployment capable. If you are using m2eclipse make sure to install the m2eclipse wtp add on so this is done automatically.
If you want to add auto-deployment to the pom.xml I recommend using the maven cargo plugin: http://cargo.codehaus.org/Maven2+plugin - it supports the major containers.
For tomcat you need to modify the tomcat-users.xml to allow auto-deployment and leave the tomcat-manager application in place. If you have startet tomcat and pointing your browser to http://localhost:8080/manager/html/list it should either tell you to login or what to add to that file.
The configured user is then used in the configuration to deploy the war file via the tomcat-manager using the mvn cargo:deploy goal. The configuration has to be added to the pom.xml using war as packaging, not to the parent-pom.xml

adding external jar files to OSGI

I have created an OSGi bundle and I want to add two external jar files to it called mediasenseplatform.jar and tinyos.jar So I added this line into my manifest file:
Bundle-ClassPAth:.,mediasenseplatform.jar,tinyos.jar
but it doesn't work and I don't see these files in my bundle jar file. How can I solve this problem?
OSGi doesn't make jar files, it is a platform for deploying and running them. If you want to include these jars in your bunde (which is just another jar) then you have to put them in there yourself.
There are build tools like maven which can do this for you.
You may also want to take a look at this related question.

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

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.

Resources