Tuesday, April 23, 2013

Generating p2-repo for custom WSO2 Features, and Components

Here, I'm going to discuss how to generate a p2-repo for custom, user-written WSO2 components, and features. This can be easily achieved using the maven plugin, carbon-p2-plugin, that WSO2 have written.
First, you may have a look at Creating-your-own-wso2-carbon-components webinar to know how to write carbon components, and a feature for those components. It covers quite a lot of basics, and best practices as well.
Now, to install these features to WSO2 products like WSO2 Enterprise Service Bus, you need to generate a p2-repository. Then, you can add that p2-repo via the "Feature Management" utility in management console, and install the features you want. p2-repo concept comes from the underline Eclipse equinox project that WSO2 products use. In the following I will tell you how to generate a p2-repo for your features.
  • Simply create a new maven project (packaging: pom)
  • Add carbon-p2-plugin as a maven plugin
  • Then set the features you want to publish under the carbon-p2-plugin plugin configuration as shown in the following sample pom.xml.  
  • This sample pom.xml was copied from the p2-repo generation pom.xml of carbon 4.1.0, and I simplified it for clarity.
  • There are two sample feature definitions I have specified. Replace those featureArtifactDef with your own feature definitions. The format is $groupId:$artifactId:$version.

I have tested this pom file, and it worked for me just fine. 
When you build this via maven, maven creates the target/p2-repo directory. This has the p2-repository which contains the complete p2-repo including artifacts.jar and content.jar. You can just use this folder to install features, or you can host it somewhere. There're no special requirements on hosting.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">


    <name>WSO2 Carbon - Feature Repository</name>


<!-- change the featureArtifactDef to match your needs -->



  1. have no time due to work load ? check the link and let us write your term paper.

  2. Hi Kasun, thank you for your post! I created a feature without your the repository-part. Only I want to clear things up if I understood it in the right way.
    In this path
    you can find all components and features for all products of carbon related to this tag.
    For example if I want to change a component x and only want to compile this feature, I delete all the the other folders and also in my parent-folder I only leave this feature uncommented which I need. This way it worked for me... Of course the feature was only installed locally to my Maven-Repository.
    So the big advantage of the p2-repo plugin is that you can define a repository to install the feature, right? But where is the difference to a maven release:perform process?
    Another question which came up: the example does point to a local repository as well, so if I want to install a feature into my WSO2-server I have to point it to my local repository?
    Thanks in advance for any help!