How to create a bundle of OSGi based on Maven in eclipse

Source: Internet
Author: User
Tags xmlns sonatype

First, the Environment preparation

1. Download and unzip eclipse

2. Download and install the JDK and configure the environment variables

Open the System Properties panel (right-click on "My Computer" → "properties" on the desktop), click Advanced System Settings , click Environment Variables , create a new variable in the system variable , variable name: java_home, variable value: \ C Program files\java\jdk1.6.0_10--OK. Then edit the path variable and add%java_home%\bin to the front.

Note: C:\Program files\java\jdk1.6.0_10 is the specific installation path for the JDK.

Verify the configuration of the JDK installation and environment variables:

Start-Enter CMD in the run to enter the DOS interface

C:\Users\ your computer user name >echo%java_home%

C:\Users\ your computer user name >java–version

The information is correct.

3. Download the MAVEN installation file and configure the environment variables

download: url http://maven.apache.org/download.html, download apache-maven-3.0-bin.zip.

Local Installation: extract the installation files to the directory you specified, such as: D:\bin, then the MAVEN installation directory is D:\bin\apache-maven-3.0

Set Environment variables:

Configure the MAVEN installation in the operating system environment.

Open the System Properties panel (right-click on "My Computer" → "properties" on the desktop), click Advanced System Settings , click Environment Variables , create a variable in the system variable named M2_home, The variable value is MAVEN's installation directory D:\bin\apache-maven-3.0. Click OK , then find a variable named path in the system variable, add%m2_home%\bin at the end of the value of the variable, and note that multiple values need to be separated by semicolons, then click OK . At this point, the environment variable setting is complete,

Run the following command to check the installation of Maven:

C:\Users\Juven xu>Echo%m2_home%

C:\Users\Juven xu>mvn-v

4. Install the Maven plugin in eclipse.

If the IDE is not eclipse but an STS, this step can be skipped because the MAVEN plugin has been inherited from the Sts.

The MAVEN plugin is installed via the install New Software under the Help menu of Eclipse, and then in the Open window, click on the "Add" button on the right side of work with "add Repository" in the popup. window and enter name (M2eclipse), enter the URL of the Maven plugin in location: http://m2eclipse.sonatype.org/sites/m2e

Install MAVEN add-ons in eclipse with the same steps as above

Website: Http://m2eclipse.sonatype.org/sites/m2e-extras

5. Install PAX cursor plugin. After the plugin is loaded, in the run configuration in Eclipse, the Pax Runner page appears after selecting the OSGi framework , where you select the Pom file of the OSGi bundle to run to execute the run OSGi Bundle

Website: http://www.ops4j.org/pax/eclipse/update/

Second, build maven bundles and turn them into OSGi bundle runs. (Take a simple helloworld as an example)

1. New Project Parent bundle.

A) New--project--maven--maven Project--next in Eclipe

Tick Create a simple project--next

In the New Maven Project window, enter the Gav for the parent bundle (that is, group ID, Artifact ID, Version), and packaging (note that the parent bundle must choose the pom, and the child bundle can choose Maven Plugin

Click Finish.

b) Create a new project sub-bundle.

The steps are the same as the new parent bundle, unlike the individual configuration values in new Maven project.

The group ID is the same so that the parent and child can be in the same group.

Artifact ID is different (the value of the parent and any one child bundle must be unique and therefore different)

Same version

Packaging different (the packaging of a sub bundle can be Maven plugin or jar, war, etc.). Once built, it is uniformly modified in the Pom file as bundles to convert maven bundles into OSGi bundles)

c) Configure the child bundle in the parent bundle's Pom file

Open the Pom.xml file of the parent bundle, and it is a good idea to add the relative paths of all child bundles and parent bundles under the Pav of the parent bundle, among the project pairs. Such as

<modules>

<module>, .... /projectname.intf.manageintf</module>

</modules>

Where projectname.intf.manageintf is also the artifact Id of the child bundle

The entire Pom.xml file for the parent bundle is as follows:

<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/xsd/maven-4.0.0.xsd" >

<modelVersion>4.0.0</modelVersion>

<groupId>com.companyname.projectname</groupId>

<artifactId>projectname</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>pom</packaging>

<name>ProjectName</name>

<modules>

<module>, .... /projectname.intf.manageintf</module>

</modules>

</project>

d) Convert the bundle from MAVEN bundle to OSGi bundle

Ø add dependencies in the Pom.xml file of the sub bundle

<dependencies>

<dependency>

<groupId>org.apache.felix</groupId>

<artifactId>org.osgi.core</artifactId>

<version>1.0.0</version>

</dependency>

</dependencies>

Ø in the Pom.xml file of the sub bundle, configure the group ID org.apache.felix,artifact ID to maven-bundle-plugin plugin, and develop bundles of bundle-activator. The packaging value of the sub bundle is also modified to be bundle.

The entire pom.xml file for the child bundle is as follows:

<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/xsd/maven-4.0.0.xsd" >

<modelVersion>4.0.0</modelVersion>

<parent>

<artifactId>projectname</artifactId>

<groupId>com.companyname.projectname</groupId>

<version>0.0.1-SNAPSHOT</version>

</parent>

<groupId>com.companyname.projectname</groupId>

<artifactId>projectname.intf.manageintf</artifactId>

<version>0.0.1-SNAPSHOT</version>

<packaging>bundle</packaging>

<name>projectname Intf manageintf</name>

<build>

<plugins>

<plugin>

<groupId>org.apache.felix</groupId>

<artifactId>maven-bundle-plugin</artifactId>

<extensions>true</extensions>

<configuration>

<instructions>

<bundle-activator>com.companyname.projectname.intf.manageintf.activator.activator</bundle-activator >

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.