码迷,mamicode.com
首页 > 其他好文 > 详细

使用maven开发OSGI例子

时间:2015-07-28 13:01:42      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:osgi   maven   

一:创建maven项目,在pom.xml里面加入如下依赖

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

com.lala.Activator.java为

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----------");
	}
}


二:配置插件

方法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>


然后,执行mvn package,即可生成含有MANIFEST.MF文件的jar


方法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>


然后,执行

mvn clean org.apache.felix:maven-bundle-plugin:bundle , 即可生成含有MANIFEST.MF文件的jar


版权声明:本文为博主原创文章,未经博主允许不得转载。

使用maven开发OSGI例子

标签:osgi   maven   

原文地址:http://blog.csdn.net/mn960mn/article/details/47103289

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!