понедельник, 22 февраля 2010 г.

Simple-XML with OSGi

For me these weekends was almost a final step of our project transformations with OSGi and of cause there were a lot of problems. One of these problems was that there are libraries that don't have bundle representation for OSGi systems. Thanks God, for me it was only the one library: Simple-XML. So I had to recompile it using maven-bundle-plugin from Apache.


Steps to do it yourself:

  1. Download sources from here
  2. Write a new pom.xml and package a new bundle

Here is my pom.xml for this library:

<project 
 xmlns="http://maven.apache.org/POM/4.0.0"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
 
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.simpleframework</groupId>
  <artifactId>simple-xml</artifactId>
  <version>2.3</version>
  <packaging>bundle</packaging>
  <name>Simple XML</name>
  <url>http://simple.sourceforge.net</url>
  <description>Simple is a high performance XML serialization and configuration framework for Java</description>
  <licenses>
    <license>
      <name>The Apache Software License, Version 2.0</name>
      <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
      <distribution>repo</distribution>
    </license>
  </licenses>
  
  <build>
   <sourceDirectory>src/</sourceDirectory>
<finalName>${project.groupId}.${project.artifactId}-${project.version}</finalName>
   <plugins>
    <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-jar-plugin</artifactId>
   <configuration>
    <archive>
     <addMavenDescriptor>false</addMavenDescriptor>
    </archive>
   </configuration>
  </plugin> 
    <plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-compiler-plugin</artifactId>
   <configuration>
    <encoding>UTF-8</encoding>
    <source>1.5</source>
    <target>1.5</target>
   </configuration>
  </plugin>
    <plugin>            
   <groupId>org.apache.felix</groupId>
   <artifactId>maven-bundle-plugin</artifactId>
   <extensions>true</extensions>
   <configuration>
     <instructions>
      <Export-Package>org.simpleframework.xml.*</Export-Package>
    <Private-Package>org.simpleframework.xml.*</Private-Package>
     </instructions>
   </configuration>
  </plugin>
   </plugins>
  </build>
  
 <dependencies>
  <dependency>
       <groupId>stax</groupId>
       <artifactId>stax-api</artifactId>
       <version>1.0.1</version>
       <scope>compile</scope>
     </dependency>
     
     <dependency>
       <groupId>stax</groupId>
       <artifactId>stax</artifactId>
       <version>1.2.0</version>
       <scope>compile</scope>
     </dependency>
     
     <dependency>
   <groupId>org.osgi</groupId>
   <artifactId>osgi_R4_core</artifactId>
   <version>1.0</version>
   <scope>provided</scope>
   <optional>true</optional>
  </dependency>
  <dependency>
   <groupId>org.osgi</groupId>
   <artifactId>osgi_R4_compendium</artifactId>
   <version>1.0</version>
   <scope>provided</scope>
   <optional>true</optional>
  </dependency>
 </dependencies>
</project>

As you can see I've removed all the tests from my pom.xml. If you want to add tests to this project it's important to edit a testSourceDirectory in the same way as I did it with sourceDirectory cause by default maven search for src/main/java and sources for this project is just in src


Downloads

For those who don't want to mess with all this recompilation stuff here are links to download this bundle from my google-docs


Installation

After you download it or do it yourself you'll need to install it in your local or companies repository. To do so simply invoke this line of code in your shell
mvn install:install-file -DgroupId=org.simpleframework -DartifactId=org.simpleframework.simple-xml -Dversion=2.3 -Dpackaging=jar -Dfile=org.simpleframework.simple-xml.2.3.jar


Usage

In your maven project you'll need to add these lines:

<dependency>
 <groupId>org.simpleframework</groupId>
 <artifactId>org.simpleframework.simple-xml</artifactId>
 <version>2.3</version>
</dependency>

P.S.

During all the time I was transfering my project to OSGi world I used THE GREATEST MAVEN BUNDLE REPOSITORY

Have a nice code :)