2014-02-13 74 views
1

我需要創建一個OSGi包包括依賴關係,我使用maven具組件插件,這是我的pom.xml構建OSGi包包括與Maven的組裝插件依賴性

<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> 
    <artifactId>logstat</artifactId> 
    <packaging>bundle</packaging> 
    <name>Log Stat Demo</name> 
    <version>1.0</version> 
    <groupId>org.test</groupId> 
    <dependencies> 
     <dependency> 
      <groupId>org.jruby</groupId> 
      <artifactId>yecht</artifactId> 
      <version>1.0</version> 
     </dependency> 
     <dependency> 
      <groupId>org.codehaus.groovy</groupId> 
      <artifactId>groovy-json</artifactId> 
      <version>2.2.1</version> 
     </dependency> 
    </dependencies> 
    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <version>2.4.0</version> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
         <Export-Package>activator.*,service.*,impl.*</Export-Package> 
         <Bundle-Activator>activator.Activator</Bundle-Activator> 
        </instructions> 
       </configuration> 
      </plugin> 
      <plugin> 
       <artifactId>maven-assembly-plugin</artifactId> 
       <configuration> 
        <archive> 
         <manifest> 
          <addClasspath>true</addClasspath> 
          <mainClass>activator.Activator</mainClass> 
         </manifest> 
        </archive> 
        <descriptorRefs> 
         <descriptorRef>jar-with-dependencies</descriptorRef> 
        </descriptorRefs> 
       </configuration> 
       <executions> 
        <execution> 
         <id>make-my-jar-with-dependencies</id> 
         <phase>package</phase> 
         <goals> 
          <goal>single</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 
    </build> 
</project> 

當我運行Maven構建,它創造了2瓶文件,一個具有依賴性和一個沒有

但在一個與屬地,MANIFEST.MF不包括OSGi的配置,如:

Manifest-Version: 1.0 
Bnd-LastModified: 1392281245886 
Build-Jdk: 1.6.0_45 
Built-By: myname 
Bundle-Activator: activator.Activator 
Bundle-ManifestVersion: 2 
Bundle-Name: test 
Bundle-SymbolicName: org.wiperdog.logstat 
Bundle-Version: 1.0.0 
Created-By: Apache Maven Bundle Plugin 
Export-Package: activator;uses:="org.osgi.framework";version="1.0.0",ser 
vice;version="1.0.0",impl;uses:="org.osgi.framework,service";version="1 
.0.0" 
Import-Package: org.jruby.embed;version="[1.7,2)",org.jruby.embed.osgi;v 
ersion="[1.7,2)",org.osgi.framework;version="[1.6,2)" 
Tool: Bnd-2.1.0.20130426-122213 

它只是有索姆e基本罐配置,不是OSGi捆綁:

Manifest-Version: 1.0 
Archiver-Version: Plexus Archiver 
Created-By: Apache Maven 
Build-Jdk: 1.6.0_45 
Main-Class: activator.Activator 

那麼,我該如何配置?

+0

那麼把你的依賴捆內(雖然是可能的,如果你的私人包)肯定是不推薦的。 OSGi全都是關於模塊化的。爲什麼你想把所有的依賴關係放在包中? – codesalsa

+0

是什麼,爲什麼你用匯編插件的原因是什麼? maven-bundle-plugin具有嵌入依賴功能。有了這一點,你可以控制,這包應該從嵌入式依賴出口。 –

+0

謝謝,我希望把一些依賴類,因爲我想在OSGi環境運行一些Ruby腳本和腳本需要使用log4j的從一些類,所以我需要包括類似:需要「org.apache.log4j.spi。 LoggingEvent所」 – Ryo

回答

11

這很簡單,以下內容添加到您的配置:

<Embed-Dependency>dependencies</Embed-Dependency> 

這基本上是它。 完整的文檔,可以在Felix-Maven-Bundle-Plugin 和更多的細節如何BND的作品可以在aqute

中找到關於,包括最佳做法被發現。如果它的東西,只是你的應用需求,並大多隱匿,嵌入這些依賴關係可以是一個有效的解決方案。 如果要重複使用這個東西,你應該考慮創建一個「陰影」捆綁