我目前正在尝试 bundle 一个非 OSGI maven 项目。现在,我有类似的东西,
<?xml version="1.0" encoding="UTF-8"?>
<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>
<!-- The Basics -->
<artifactId>Project1</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>internal.commons</groupId>
<artifactId>internalcommons</artifactId>
<version>1.5</version>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<parent>
<groupId>internal</groupId>
<artifactId>jar-project</artifactId>
<version>1.0</version>
</parent>
<name>Project 1</name>
<build>
<directory>${basedir}/bundles</directory>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>1.0</Bundle-Version>
<Import-Package>*;resolution:=optional</Import-Package>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
然而,我的非 OSGI 包依赖于各种不同的 jar,其中一些 jar 也有依赖性。当我 bundle 非 OSGI maven 项目时,我只能获得该 bundle 的直接依赖项,当我使用 bundleall 时,我收到与 xml-apis:xml-apis:jar:2.6.2 相关的错误。如果没有其他选择但依赖项太多,我可以创建所有依赖项的 bundle 。
如有任何帮助,我们将不胜感激!
最佳答案
嗯,
根据发布的堆栈跟踪,central repo 中没有 xml-apis:xml-apis:2.6.2
Artifact .我想应该是xerces:xmlParserAPIs:2.6.2 .
这是更新的 pom,它没有嵌入 deps 的问题:
<?xml version="1.0" encoding="UTF-8"?>
<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>
<!-- The Basics -->
<groupId>internal</groupId>
<artifactId>Project1</artifactId>
<version>1.0</version>
<packaging>bundle</packaging>
<name>Project 1</name>
<dependencies>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>xerces</groupId>
<artifactId>xmlParserAPIs</artifactId>
<version>2.6.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>${project.name}</Bundle-Name>
<Bundle-Version>1.0</Bundle-Version>
<Import-Package>*;resolution:=optional</Import-Package>
<Embed-Dependency>*</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
注意使用 packaging=bundle
。要构建只需执行 mvn package
。
尽管 maven-bundle-plugin 有助于嵌入依赖项,但如果可以实现项目的更高模块化,我强烈建议您不要这样做。有带有预构建 osgi 包的 repo 协议(protocol),例如:apache servicemix bundles , spring enterprise bundle repository等
关于java - OSGI 传递依赖级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12965589/