使用 maven-bundle-plugin 包含来自 Spring XML 的依赖项

Include dependencies from Spring XML using maven-bundle-plugin

我正在使用 maven-bundle-plugin 创建 MANIFEST.MF。它可以很好地处理 java 代码中检测到的依赖项,但它会忽略 spring XML 的内容。例如,我有以下声明:

  <context:mbean-export />

  <bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

  <bean id="jpaVendorAdapter"
    class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
    <property name="databasePlatform"
      value="org.eclipse.persistence.platform.database.PostgreSQLPlatform" />
    <property name="generateDdl" value="true" />
  </bean>

所以,很明显,我的包需要导入包 org.springframework.orm.jpa.supportorg.springframework.orm.jpa.vendororg.eclipse.persistence.platform.database 和一些我什至不知道的 MBeans 处理器包。

据我所知,在我参与的一个项目中,我们使用了 Spring 和 maven-bundle-plugins 并且所有依赖项检测工作正常,所以看起来我的配置中缺少某些东西.我需要以某种方式通知 bundle 插件应该分析哪个 XML 文件。

如何让 bundle 插件检测来自 spring XML 的依赖项?

这是我的捆绑插件配置:

  <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <executions>
      <execution>
        <id>generate-resources</id>
        <goals>
          <goal>manifest</goal>
        </goals>

        <configuration>
          <instructions>
            <Bundle-Name>${project.name}</Bundle-Name>
            <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
          </instructions>
        </configuration>
      </execution>
    </executions>
  </plugin>

我不确定 maven-bundle-plugin 是否识别普通 spring 上下文。我知道它适用于蓝图上下文。无论如何,请确保您的 spring 上下文位于 META-INF/spring 中。它只会在这个位置被识别。

在任何情况下,在 OSGi 中使用 spring 不再被真正支持。唯一的生产就绪方式是 spring dm,这个项目已经死了。 Aries 蓝图中有对完整 spring 的实验性支持,但尚未达到生产级别。

OSGi 中经过验证的方法是使用蓝图(例如 Aries 蓝图)。由于现在已经有一段时间了,还有一个 Maven 插件可以在构建过程中创建蓝图 xml。所以在你的来源中你只使用注释。

Karaf Tutorial Part 1