• 使用maven开发OSGI样例


    一:创建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>
    			<manifestEntries>
    				<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

    或者把package声明为bundle 

    如:<packaging>bundle</packaging>

    然后。就能够直接使用mvn clean package


  • 相关阅读:
    Cannot allocate memory(1)
    tomcat server.xml配置属性
    HTB-靶机-Nibbles
    HTB-靶机-CrimeStoppers
    HTB-靶机-FluxCapacitor
    HTB-靶机-Bashed
    HTB-靶机-Inception
    HTB-靶机-Fulcrum
    HTB-靶机-Ariekei
    HTB-靶机-Enterprise
  • 原文地址:https://www.cnblogs.com/lytwajue/p/7301442.html
Copyright © 2020-2023  润新知