Developing OSGi examples using MAVEN

Source: Internet
Author: User

One: Create a MAVEN project and add the following dependencies to Pom.xml

<dependency>            <groupId>org.osgi</groupId>            <artifactid>org.osgi</artifactid >            <version>3.0.0</version>            <type>jar</type></dependency>

Com.lala.Activator.java for

Package Com.lala;import Org.osgi.framework.bundleactivator;import Org.osgi.framework.bundlecontext;public class Activator implements Bundleactivator{public void Start (Bundlecontext context) throws Exception {System.out.println ("-- ---------start----------");} public void Stop (Bundlecontext context) throws Exception {System.out.println ("-----------Stop----------");}}


Two: Configure plug-ins

Method 1:

<plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-jar-plugin</ artifactid><version>2.3.1</version><configuration><archive><manifest>< Addclasspath>true</addclasspath><classpathprefix>lib/</classpathprefix></manifest> <manifestentries><class-path>.</class-path><bundle-manifestversion>2</ Bundle-manifestversion><bundle-name>${project.groupid}.${project. Artifactid}</bundle-name><bundle-symbolicname>${project.groupid}.${project. artifactid}</bundle-symbolicname><bundle-version>${project.version}</bundle-version>< bundle-vendor>${project.groupid}</bundle-vendor><bundle-activator>com.lala.activator</ Bundle-activator><export-package>com.lala.api</export-package><import-package> Org.osgi.framework</import-package></manifestentries></archive></configuration></plUgin> 


Then, execute the MVN package to generate the jar containing the MANIFEST.MF file


Method 2:

<plugin><groupid>org.apache.felix</groupid><artifactid>maven-bundle-plugin</ Artifactid><version>2.5.4</version><extensions>true</extensions><configuration ><instructions><bundle-manifestversion>2</bundle-manifestversion><bundle-name>${ Project.groupid}.${project. Artifactid}</bundle-name><bundle-symbolicname>${project.groupid}.${project. artifactid}</bundle-symbolicname><bundle-version>${project.version}</bundle-version>< Bundle-vendor>${project.groupid}</bundle-vendor><export-package>com.lala.api</export-package ><Bundle-Activator>com.lala.Activator</Bundle-Activator><Import-Package> Org.osgi.framework</import-package></instructions></configuration></plugin>


Then, execute

MVN clean org.apache.felix:maven-bundle-plugin:bundle to generate a jar containing MANIFEST.MF files


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Developing OSGi examples using MAVEN

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.