作为能够快速过渡到 OSGi 的临时措施,我需要创建一个包含我所有库的 jar。我所做的是将所有 jar 库放在 src/main/resources 中,以便它们最终位于创建的 jar 的根目录中。我遇到的问题是告诉 maven-bundle-plugin 导出 jars 中的所有包。所以基本上,我想将我所有的库暴露给其他 OSGi 包
这是我在 POM 中尝试的第一件事
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>*</Export-Package>
<Bundle-Name>${project.artifactId}</Bundle-Name>
<Bundle-Version>${project.version}</Bundle-Version>
</instructions>
</configuration>
</plugin>
</plugins>
</build>`
我试图导出所有的东西。但似乎唯一像这样导出的是两个 osgi 依赖项,而不是资源中的 jars
我有一百多个库,所以我试图找到一种自动化的方法来填充
<Export-Package>
指令,而不是手动添加每个库的包。 eclipse 以某种方式在插件开发环境中执行此操作,但我需要使用 maven 执行此操作。捆绑插件是否可以做到这一点?如果 jar 被添加到 <Bundle-ClassPath>
中,则额外加分
最佳答案
您必须在 pom.xml 中添加 jar 作为依赖项,然后在
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<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>
<Bundle-Activator>your.activator.package.Activator</Bundle-Activator>
<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>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
还要添加以下内容以使一切都适用于 m2e:
参见:maven-dependency-plugin (goals “copy-dependencies”, “unpack”) is not supported by m2e
<pluginManagement>
<plugins>
<!-- Ignore/Execute plugin execution -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<!-- copy-dependency plugin -->
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>copy-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
还要添加以下内容以使其与 Eclipse PDE 一起使用(取自 Apache Felix website ):
<profiles>
<profile>
<activation>
<property>
<name>m2e.version</name>
</property>
</activation>
<properties>
<osgi-version-qualifier>qualifier</osgi-version-qualifier>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<configuration>
<!-- PDE does not honour custom manifest location -->
<manifestLocation>META-INF</manifestLocation>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
关于maven - <Export-Package> 用于使用 maven-bundle-plugin 的所有资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11531152/