我使用maven-bundle-plugin从非osgi依赖创建osgi插件,我希望将这种依赖的源包含到projet构建中。
这是我从jfreechart创建OSGI包的示例,当我发布它时,我想包含jfreechart源。
<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>
<groupId>org.jfree.chart</groupId>
<artifactId>com.netappsid.org.jfree.chart</artifactId>
<version>1.0.13</version>
<name>JFreeChart OSGI</name>
<packaging>bundle</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>org.jfree.chart.*;org.jfree.data.*</Export-Package>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
<Embed-Dependency>jfreechart;inline=true</Embed-Dependency>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.13</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>com.springsource.org.jfree</artifactId>
<version>1.0.12</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>com.springsource.javax.servlet</artifactId>
<version>2.5.0</version>
</dependency>
</dependencies>
</project>
答案 0 :(得分:1)
我有同样的问题。这就是我最终做的事情:
使用maven-dependency-plugin
解压缩源代码<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-sources</id>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/sources</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<classifier>sources</classifier>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
附加使用maven-assembly-plugin构建的源工件
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>source-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>src.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
使用以下描述符(请注意,描述符id用作分类器;默认情况下附加工件):
<?xml version="1.0"?>
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>sources</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>jar</format>
</formats>
<fileSets>
<fileSet>
<directory>${project.build.directory}/sources</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
</fileSet>
</fileSets>
</assembly>
答案 1 :(得分:0)
如果我理解正确的话......
我必须自己打包许多无osg的JAR才能在OSGi应用程序中使用。使用maven-bundle-plugin
时,如果您在清单(或Export-Package
文件)中使用osgi.bnd
,则其类将包含在创建的包中。
示例:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: ACME PostgreSQL Driver Bundle
Bundle-SymbolicName: com.acme.org.postgresql
Bundle-Version: 9.0.801.jdbc4
# NB: I've imported a little too much for what is required.
Import-Package: org.postgresql*;version="9.0-801.jdbc4", \
javax*, \
org.w3c.dom, \
!org.ietf.jgss, \
!org.dom.xml.views
Export-Package: org.postgresql*;version="9.0-801.jdbc4"
Private-Package: org.w3c.dom*, org.xml*, javax*
这里,导出的包将从POM中的Maven依赖项包含在JAR中。
如果您还想包含依赖项JAR,则可以使用Embed-Dependency
:
Embed-Dependency: org.postgresql*;version="9.0-801.jdbc4"
Embed-Transitive: true
如果你正在寻找这个?
贝