我需要创建一个包含依赖项的OSGi包,我正在使用maven-assembly-plugin,这是我的pom.xml
<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 build时,它创建了2个jars文件,一个带有依赖项,一个没有
但是在具有依赖关系的那个中,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
它只是有一些基本的jar配置,而不是OSGi包:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Build-Jdk: 1.6.0_45
Main-Class: activator.Activator
那么,我该如何配置?
答案 0 :(得分:13)
这非常简单,请在配置中添加以下内容:
<Embed-Dependency>dependencies</Embed-Dependency>
基本上就是这样。 完整的文档可以在Felix-Maven-Bundle-Plugin找到 有关BND如何工作的更多详细信息,请访问aqute
关于包括的最佳实践。如果它只是您的应用程序需要并且大部分是隐藏的,那么嵌入这些依赖项可能是一个有效的解决方案。 如果你重复使用这些东西,你应该考虑创建一个“阴影”包