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
<plugin>
<groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId>
<version>1.5.2</version>
---
</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" 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"> <parent> <groupId>org.wso2.carbon</groupId> <artifactId>carbon-features</artifactId> <version>4.1.0</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>mysample-feature-repository</artifactId> <version>4.1.0</version> <packaging>pom</packaging> <name>WSO2 Carbon - Feature Repository</name> <build> <plugins> <plugin> <groupId>org.wso2.maven</groupId> <artifactId>carbon-p2-plugin</artifactId> <version>1.5.2</version> <executions> <execution> <id>2-p2-repo-generation</id> <phase>package</phase> <goals> <goal>p2-repo-gen</goal> </goals> <configuration> <p2AgentLocation>${basedir}/target/p2-agent</p2AgentLocation> <metadataRepository>file:${basedir}/target/p2-repo</metadataRepository> <artifactRepository>file:${basedir}/target/p2-repo</artifactRepository> <publishArtifacts>true</publishArtifacts> <publishArtifactRepository>true</publishArtifactRepository> <featureArtifacts> <!-- change the featureArtifactDef to match your needs --> <featureArtifactDef> org.wso2.carbon:org.wso2.carbon.service.mgt.feature:4.1.0 </featureArtifactDef> <featureArtifactDef> org.wso2.carbon:org.wso2.carbon.registry.core.feature:4.1.0 </featureArtifactDef> </featureArtifacts> </configuration> </execution> </executions> </plugin> </plugins> </build> </project>
have no time due to work load ? check the link and let us write your term paper.
ReplyDeleteHi 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.
ReplyDeleteIn this path
http://svn.wso2.org/repos/wso2/carbon/platform/tags/4.0.7/
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!
Best,
Johannes