我是整个 OSGi 的新手,我的任务是从现有的 maven 项目中创建一个 OSGi Bundle。
首先,我决定选择最小的部分并从它开始:
这是 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>cross</artifactId>
<groupId>net.sf.maltcms</groupId>
<version>1.2.12-SNAPSHOT</version>
</parent>
<artifactId>cross-main</artifactId>
<packaging>jar</packaging>
<name>cross-main</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cross-annotations</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cross-event</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cross-tools</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cross-exception</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cross-main-api</artifactId>
<version>${project.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-asm</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.0.6.RELEASE</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-expression</artifactId>
<version>3.0.6.RELEASE</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.4.6</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>cross-math</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.db4o</groupId>
<artifactId>db4o-all</artifactId>
<version>8.0.249</version>
</dependency>
<dependency>
<groupId>net.sf.mpaxs</groupId>
<artifactId>mpaxs-spi</artifactId>
<version>1.6.10</version>
</dependency>
<dependency>
<groupId>net.sf.mpaxs</groupId>
<artifactId>mpaxs-server</artifactId>
<version>1.6.10</version>
</dependency>
</dependencies>
我做了一些研究,找到了 Apache Bundle Plugin for maven 并将 pom 更改为这个
<packaging>bundle</packaging>
并添加
<build>
<plugins>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
mvn clean install 很好,我得到了一个包含清单的 jar 文件,但当然无法解析捆绑包
BundleException: The bundle "cross-main_1.2.12.SNAPSHOT [30]" could not be resolved. Reason: Missing Constraint: Import-Package: com.db4o; version="[8.0.0,9.0.0)
长话短说:将 maven 应用程序迁移到 OSGi Bundle 的可能性是什么?
特别是如何管理依赖项