domingo, 13 de abril de 2014

Convert a JAR into Bundle

Personal notes on how to quickly create a bundle based on a list of jars or other dependencies. It uses the content-package and embedded maven configuration to easily deploy the bundle.

Normal and Painful Way
The most difficult way is to follow the standard way and create a manifest file with all the description available. You will also need to figure out the dependencies of your bundle. This blog will show the easy way to package a bundle with all the dependencies that you need.

Step#1: Easy Way

The project is quickly created by the classic mvn archetype. The idea is to follow the structure. 

myprojectlib/depency-pkg-libs

where myprojectlib is the root project and depency-pkg-libs the module with the declared dependencies. We will not include any other code into the folders. Also for the purposes of example, we will use the JUnit Sling Testing on the server side. This bundle is not included in the default distribution and requires JUnit as a dependency.

Step #2: Create the First module

mvn archetype:generate

Make sure you create a basic maven repository with the pom project as root.

In our case the  myprojectlib will look like:

<packaging>pom</packaging>

Step#3: Create the  Content-package
Create a package depency-pkg-libs inside the root directory. Make sure you change the packaging so that it becomes content-package

<packaging>content-package</packaging>

Step#4: Add Embedded List
To your list of build plugins, add the content-package-maven plugin

<groupId>com.day.jcr.vault</groupId>
<artifactId>content-package-maven-plugin</artifactId>

In the list of embedded element add those dependencies that you need. In my case, the junit.remote:

<embeddeds>
  <embedded>
     <groupId>org.apache.sling</groupId>
      <artifactId>org.apache.sling.junit.remote</artifactId>
     <target>${package.root}/install</target>
  </embedded>
</embeddeds>

You should also add the same artifacts listed in embedded to your list of dependencies. Otherwise those will not be installed.

     <dependency>
          <groupId>org.apache.sling</groupId>
          <artifactId>org.apache.sling.junit.remote</artifactId>
          <version>1.0.6</version>
          <scope>provided</scope>
      </dependency>

Actual Code
You can check the actual code from bitbucket. The meat is in the pom.
References
This blog is based on the following resources.


No hay comentarios:

Publicar un comentario