Sunday, June 28, 2015

Add third party library to custom feature developed for WSO2 product.


This is a great article which explain how to write a custom feature for WSO2 product.(http://wso2.com/library/articles/2013/09/how-to-build-a-custom-stack-with-wso2-carbon/)

This blog post is going to explain how to add third party library to your custom feature.

1. You can create orbit bundle from that third part library.

Eg : This[i] is to make the Apache POI library as OSGI bundle.

[i] https://svn.wso2.org/repos/wso2/carbon/orbit/branches/4.2.0/poi/3.9.0.wso2v1/pom.xml

2. Build your orbit bundle. (use maven)

3. Then you need to add that dependency to student-manager/features/org.wso2.carbon.student.mgt.server.feature/pom.xml file.

Eg:
<dependency>
       <groupId>org.apache.poi.wso2</groupId>
       <artifactId>poi</artifactId>
       <version>3.9.0.wso2v1</version>
</dependency> 

4. Add new <bundleDef> entry inside the <bundles> element in student-manager/features/org.wso2.carbon.student.mgt.server.feature/pom.xml file.

The format of the <bundleDef> should be , <bundleDef>[groupId]:[artifactId]</bundleDef>

Eg:
<bundleDef>org.apache.poi.wso2:poi</bundleDef>

org.apache.poi.wso2 - groupId of above dependency
poi                           - artifactId of above dependency

5. Build the student-manager project again, now you should see that poi_3.9.0.wso2v1.jar file in student-manager/repository/target/p2-repo/plugins directory.

6. Finally when you install student-manager feature to WSO2 server (from that p2-repo), that third party library(poi_3.9.0.wso2v1.jar) will automatically install.