I found a situation where an osgi bundle made a reference to an expected system library that wasn't there, but since the bundle did not include the dependency as an osgi reference, the framework (Felix in this case) threw a 'Class Not Found' exception.
Turns out, our friends at the OSGi Alliance have a solution for this kind of problem.
org.osgi.framework.bootdelegation=package
Essentially, packages specified will bypass the osgi environment and go directly to the VM.
Seems like this feature should be used sparingly and only when necessary.
Showing posts with label osgi. Show all posts
Showing posts with label osgi. Show all posts
Monday, March 28, 2011
Saturday, March 26, 2011
How to build a basic Pax-Runner application with Maven that utilizes spring-dm
My goal is to create a Maven based solution that can automatically assemble a pax-runner driven application that is ready to be deployed.
To make this work with a larger application, there should be an outer pom that includes this and any other bundles as modules. This should be the last module processed, the assembly process will pick up on the other modules built at the same time.
Directory Structure:
- pom.xml
- src
- main
- etc
- assembly
- paxrunner-assembly.xml
- scripts
- run.bat - for windows
- run.sh - for *nix
- assembly
- etc
- main
To start I created a Maven pom file that has pax-runner as a dependency and references a custom assembly file.
pom.xml
<dependencies>
<dependency>
<groupId>org.ops4j.pax.runner</groupId>
<artifactId>pax-runner</artifactId>
<version>${pax-runner.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>create-target</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/etc/assembly/paxrunner-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependency>
<groupId>org.ops4j.pax.runner</groupId>
<artifactId>pax-runner</artifactId>
<version>${pax-runner.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>create-target</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src/main/etc/assembly/paxrunner-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
The assembly file will tell Maven how to package the final output. The xml is fairly easy to read, see the maven-assembly-plugin documentation for specifics. The one thing worth calling out is the exclusion of the spring and related libraries, this is because pax-runner already has a built in profile that will download and wire them up properly.
paxrunner-assembly.xml
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>distribution</id>
<formats>
<format>dir</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>src/main/etc/scripts/run.sh</source>
<fileMode>0777</fileMode>
</file>
<file>
<source>src/main/etc/scripts/run.bat</source>
<fileMode>0777</fileMode>
</file>
</files>
<moduleSets>
<moduleSet>
<binaries>
<unpack>false</unpack>
<includeDependencies>true</includeDependencies>
<outputDirectory>lib/module-bundles</outputDirectory>
<dependencySets>
<!-- 3rd party libraries -->
<dependencySet>
<outputDirectory>lib/required-bundles</outputDirectory>
<excludes>
<exclude>org.springframework:org.springframework.core</exclude>
<exclude>org.springframework:org.springframework.aop</exclude>
<exclude>org.springframework:org.springframework.asm</exclude>
<exclude>org.springframework:org.springframework.beans</exclude>
<exclude>org.springframework:org.springframework.context</exclude>
<exclude>org.springframework:org.springframework.context.support</exclude>
<exclude>org.springframework:org.springframework.expression</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.aopalliance:*</exclude>
<exclude>org.apache.commons:*.logging</exclude>
</excludes>
</dependencySet>
</dependencySets>
</binaries>
</moduleSet>
</moduleSets>
<dependencySets>
<!-- Adds pax-runner to root of distribution -->
<dependencySet>
<scope>provided</scope>
<includes>
<include>org.ops4j.pax.runner:pax-runner</include>
</includes>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
</dependencySets>
</assembly>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
<id>distribution</id>
<formats>
<format>dir</format>
<format>zip</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>src/main/etc/scripts/run.sh</source>
<fileMode>0777</fileMode>
</file>
<file>
<source>src/main/etc/scripts/run.bat</source>
<fileMode>0777</fileMode>
</file>
</files>
<moduleSets>
<moduleSet>
<binaries>
<unpack>false</unpack>
<includeDependencies>true</includeDependencies>
<outputDirectory>lib/module-bundles</outputDirectory>
<dependencySets>
<!-- 3rd party libraries -->
<dependencySet>
<outputDirectory>lib/required-bundles</outputDirectory>
<excludes>
<exclude>org.springframework:org.springframework.core</exclude>
<exclude>org.springframework:org.springframework.aop</exclude>
<exclude>org.springframework:org.springframework.asm</exclude>
<exclude>org.springframework:org.springframework.beans</exclude>
<exclude>org.springframework:org.springframework.context</exclude>
<exclude>org.springframework:org.springframework.context.support</exclude>
<exclude>org.springframework:org.springframework.expression</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.aopalliance:*</exclude>
<exclude>org.apache.commons:*.logging</exclude>
</excludes>
</dependencySet>
</dependencySets>
</binaries>
</moduleSet>
</moduleSets>
<dependencySets>
<!-- Adds pax-runner to root of distribution -->
<dependencySet>
<scope>provided</scope>
<includes>
<include>org.ops4j.pax.runner:pax-runner</include>
</includes>
<outputFileNameMapping>${artifact.artifactId}.${artifact.extension}</outputFileNameMapping>
</dependencySet>
</dependencySets>
</assembly>
Finally for the scripts, these do nothing more than start up pax-runner and pass in any directories of bundles or configuration files.
run.sh
java -jar pax-runner.jar --profiles=spring.dm --workingDirectory=. scan-dir:lib/required-bundles scan-dir:lib/module-bundles
run.bat
@echo off
call java -jar pax-runner.jar --profiles=spring.dm --workingDirectory=. scan-dir:lib/required-bundles scan-dir:lib/module-bundles %1 %2 %3
call java -jar pax-runner.jar --profiles=spring.dm --workingDirectory=. scan-dir:lib/required-bundles scan-dir:lib/module-bundles %1 %2 %3
Subscribe to:
Posts (Atom)