【发布时间】:2014-03-12 02:52:49
【问题描述】:
我需要创建一个包含依赖项的 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
那么,我该如何配置呢?
【问题讨论】:
-
当然不建议将您的依赖项放在一个包中(如果您是私有包,则可能)。 OSGi 是关于模块化的。为什么要将所有依赖项放在包中?
-
你使用汇编插件的原因是什么? maven-bundle-plugin 具有嵌入依赖功能。有了它,您可以控制应该从嵌入式依赖项中导出哪个包。
-
谢谢,我想放一些依赖类,因为我想在 osgi 环境中运行一些 ruby 脚本,并且脚本需要使用 log4j 中的一些类,所以我需要包含类似:require "org .apache.log4j.spi.LoggingEvent"
标签: maven osgi maven-assembly-plugin