当前位置: 首页 > 知识库问答 >
问题:

带有maven-bundle-plugin的OSGI JAR包

南宫松
2023-03-14
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
<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>
[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
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: xxxx
Created-By: Apache Maven 3.3.9
Build-Jdk: 1.8.0_65

请帮忙。

共有1个答案

彭阳荣
2023-03-14

这起作用了:

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

结果包包含target\dependency\guava-18.0.jar

舱单:

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
 类似资料: