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