2016-03-31 15 views
1

Ich versuche einige JARs in ein OSGI-Bundle einzubetten, die kein entsprechendes OSGI-Bundle enthalten, so dass andere OSGI-Bundles auf sie verweisen können.OSGI-Bundle von JARs mit maven-bundle-plugin

Ich habe viele Vorschläge gefolgt, aber nichts hat funktioniert. Mein letzter Versuch basiert auf: <Export-Package> for all resources using maven-bundle-plugin

Wenn ich den aufgerufenen OSGi-Paket nicht die erwartete enthält eingebettete jar:

META-INF 
META-INF\MANIFEST.MF 
META-INF\maven 
META-INF\maven\com.mycompany 
META-INF\maven\com.mycompany\osgi-bundle-test 
META-INF\maven\com.mycompany\osgi-bundle-test\pom.properties 
META-INF\maven\com.mycompany\osgi-bundle-test\pom.xml 

Hier ist meine pom.xml:

<dependencies> 
    <dependency> 
     <groupId>com.google.guava</groupId> 
     <artifactId>guava</artifactId> 
     <version>18.0</version> 
    </dependency> 
</dependencies> 

<build> 
    <defaultGoal>install</defaultGoal> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-dependency-plugin</artifactId> 
      <version>2.8</version> 
      <executions> 
       <execution> 
        <id>copy-dependencies</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>copy-dependencies</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>3.0.1</version> 
      <extensions>true</extensions> 
      <configuration> 
       <manifestLocation>META-INF</manifestLocation> 
       <instructions> 
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
        <Bundle-Version>${project.version}</Bundle-Version> 
        <Export-Package>*</Export-Package> 
        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
        <Embed-Directory>target/dependency</Embed-Directory> 
        <Embed-StripGroup>true</Embed-StripGroup> 
        <Embed-Transitive>true</Embed-Transitive> 
       </instructions> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

Hier ein Ausschnitt aus MVN ist sauber installieren:

[INFO] --- maven-dependency-plugin:2.8:copy-dependencies (copy-dependencies) @ osgi-bundle-test --- 
[INFO] Copying guava-18.0.jar to <local-dir>\target\dependency\guava-18.0.jar 
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ osgi-bundle-test --- 
[INFO] Building jar: <local-dir>\target\osgi-bundle-test-0.0.1-SNAPSHOT.jar 
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ osgi-bundle-test --- 
[INFO] Installing <local-dir>\target\osgi-bundle-test-0.0.1-SNAPSHOT.jar to <repo-dir>\com\mycompany\osgi-bundle-test\0.0.1-SNAPSHOT\osgi-bundle-test-0.0.1-SNAPSHOT.jar 
[INFO] Installing <local-dir>\pom.xml to <repo-dir>\com\mycompany\osgi-bundle-test\0.0.1-SNAPSHOT\osgi-bundle-test-0.0.1-SNAPSHOT.pom 

Inhalt des MANIFEST.MF:

Manifest-Version: 1.0 
Archiver-Version: Plexus Archiver 
Built-By: xxxx 
Created-By: Apache Maven 3.3.9 
Build-Jdk: 1.8.0_65 

Bitte helfen.

+0

Was Sie im Export-Package und Import-Package Ihrer Manifest sehen? –

+0

Das Manifest enthält keines von beiden. Ich habe meine ursprüngliche Frage mit dem Inhalt des Manifests aktualisiert. –

Antwort

0

Das funktionierte:

<modelVersion>4.0.0</modelVersion> 
    <groupId>com.mycompany</groupId> 
    <artifactId>osgi-bundle-test-v2</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <packaging>bundle</packaging> 

    <dependencies> 
     <dependency> 
      <groupId>com.google.guava</groupId> 
      <artifactId>guava</artifactId> 
      <version>18.0</version> 
      <scope>runtime</scope> 
     </dependency> 
    </dependencies> 

    <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.felix</groupId> 
       <artifactId>maven-bundle-plugin</artifactId> 
       <version>3.0.1</version> 
       <extensions>true</extensions> 
       <configuration> 
        <instructions> 
         <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
         <Bundle-Version>${project.version}</Bundle-Version> 
         <Export-Package>*</Export-Package> 
         <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
         <Embed-Directory>target/dependency</Embed-Directory> 
        </instructions> 
       </configuration> 
      </plugin> 
     </plugins> 
    </build> 

Daraus resultierende Bündel enthält target \ Abhängigkeit \ Guave-18.0.jar

Manifest:

Manifest-Version: 1.0 
Bnd-LastModified: 1460052892382 
Build-Jdk: 1.7.0_79 
Built-By: myId 
Bundle-ClassPath: .,target/dependency/guava-18.0.jar 
Bundle-ManifestVersion: 2 
Bundle-Name: osgi-bundle-test-v2 
Bundle-SymbolicName: osgi-bundle-test-v2 
Bundle-Version: 0.0.1.SNAPSHOT 
Created-By: Apache Maven Bundle Plugin 
Embed-Dependency: *;scope=compile|runtime 
Embed-Directory: target/dependency 
Embedded-Artifacts: target/dependency/guava-18.0.jar;g="com.google.guava 
";a="guava";v="18.0" 
Export-Package: com.google.common.annotations;version="18.0.0",com.googl 
e.common.base;version="18.0.0";uses:="javax.annotation",com.google.comm 
on.base.internal;version="0.0.1.SNAPSHOT",com.google.common.cache;versi 
on="18.0.0";uses:="com.google.common.base,com.google.common.collect,com 
.google.common.util.concurrent,javax.annotation",com.google.common.coll 
ect;version="18.0.0";uses:="com.google.common.base,javax.annotation",co 
m.google.common.escape;version="18.0.0";uses:="com.google.common.base,j 
avax.annotation",com.google.common.eventbus;version="18.0.0",com.google 
.common.hash;version="18.0.0";uses:="com.google.common.base,javax.annot 
ation",com.google.common.html;version="18.0.0";uses:="com.google.common 
.escape",com.google.common.io;version="18.0.0";uses:="com.google.common 
.base,com.google.common.collect,com.google.common.hash,javax.annotation 
",com.google.common.math;version="18.0.0",com.google.common.net;version 
="18.0.0";uses:="com.google.common.base,com.google.common.collect,com.g 
oogle.common.escape,javax.annotation",com.google.common.primitives;vers 
ion="18.0.0";uses:="com.google.common.base,javax.annotation",com.google 
.common.reflect;version="18.0.0";uses:="com.google.common.collect,javax 
.annotation",com.google.common.util.concurrent;version="18.0.0";uses:=" 
com.google.common.base,com.google.common.collect,javax.annotation",com. 
google.common.xml;version="18.0.0";uses:="com.google.common.escape",com 
.google.thirdparty.publicsuffix;version="0.0.1.SNAPSHOT";uses:="com.goo 
gle.common.collect",target.dependency;version="0.0.1.SNAPSHOT" 
Import-Package: com.google.common.base;version="[18.0,19)",com.google.co 
mmon.cache;version="[18.0,19)",com.google.common.collect;version="[18.0 
,19)",com.google.common.escape;version="[18.0,19)",com.google.common.ha 
sh;version="[18.0,19)",com.google.common.io;version="[18.0,19)",com.goo 
gle.common.math;version="[18.0,19)",com.google.common.primitives;versio 
n="[18.0,19)",com.google.common.reflect;version="[18.0,19)",com.google. 
common.util.concurrent;version="[18.0,19)",com.google.thirdparty.public 
suffix;version="[0.0,1)",javax.annotation,sun.misc 
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.6))" 
Tool: Bnd-3.0.0.201509101326 
0

Ich glaube, Sie müssen den Ausführungsabschnitt hinzuzufügen, um das manifest Ziel im Prozess-Klassen Phase auszuführen:

<execution> 
    <id>bundle-manifest</id> 
    <phase>process-classes</phase> 
    <goals> 
    <goal>manifest</goal> 
    </goals> 
</execution> 

wie:

 <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>3.0.1</version> 
      <extensions>true</extensions> 
      <configuration> 
       <manifestLocation>META-INF</manifestLocation> 
       <instructions> 
        <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName> 
        <Bundle-Version>${project.version}</Bundle-Version> 
        <Export-Package>*</Export-Package> 
        <Embed-Dependency>*;scope=compile|runtime</Embed-Dependency> 
        <Embed-Directory>target/dependency</Embed-Directory> 
        <Embed-StripGroup>true</Embed-StripGroup> 
        <Embed-Transitive>true</Embed-Transitive> 
       </instructions> 
      </configuration> 
      <executions> 
       <execution> 
        <id>bundle-manifest</id> 
        <phase>process-classes</phase> 
        <goals> 
         <goal>manifest</goal> 
        </goals> 
       </execution>       
      </executions> 
     </plugin> 
+0

Leider hat es nicht den Trick gemacht. In der Manifestdatei fehlen Export-Package, Import-Package und die Maven-Abhängigkeits-JAR-Datei. –