【问题标题】:How to integrate servicemix shared libraries using jbi-maven-plugin?如何使用 jbi-maven-plugin 集成 servicemix 共享库?
【发布时间】:2012-01-04 13:50:11
【问题描述】:

我使用 ServiceMix 3.5 我有多个 ServiceAssemblies,每个 ServiceAssemblies 一个 ServiceUnit。 服务单元有许多共同的库,所以我在 maven pom 中将它们标记为“提供”范围。 共享库包含我希望服务单元共享的所有库。 我按照下面的maven pom.xml的搭建但是效果是一个简单的例外:

java.lang.ClassNotFoundException: 类加载器中的 org.apache.commons.dbcp.BasicDataSource org.apache.xbean.spring.context.FileSystemXmlApplicationContext

为了让我的服务单元使用共享库中的 jar,我可以做什么(可能使用 jbi-maven-plugin)?

共享库服务单元 pom:

<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>aaa.bbb</groupId>
  <artifactId>SHARED_SU</artifactId>
  <packaging>jbi-service-unit</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <parent>
    <groupId>aaa.bbb</groupId>
    <artifactId>theParent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <build>
    <defaultGoal>install</defaultGoal>
    <plugins/>
  </build>

  <properties><componentName>servicemix-camel</componentName></properties>

  <dependencies>
  ...
  </dependencies>
</project>

共享库服务单元 pom:

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>aaa.bbb</groupId>
  <artifactId>SHARED_SA</artifactId>
  <packaging>jbi-shared-library</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <parent>
    <groupId>aaa.bbb</groupId>
    <artifactId>theParent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <dependencies>
    <dependency>
      <groupId>aaa.bbb</groupId>
      <artifactId>SHARED_SU</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>  
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <version>3.2.3</version>
        <extensions>true</extensions>
        <configuration>
          <type>service-assembly</type>
          <classLoaderDelegation>parent-first</classLoaderDelegation>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

需要使用共享库的服务单元的Pom:

<?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>
  <groupId>aaa.bbb</groupId>
  <artifactId>theServiceUnit</artifactId>
  <packaging>jbi-service-unit</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <parent>
    <groupId>aaa.bbb</groupId>
    <artifactId>theParent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <build>
    <defaultGoal>install</defaultGoal>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <version>3.2.3</version>
        <extensions>true</extensions>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    ... <!-- all "PROVIDED" in scope-->
  <properties>
    <componentName>servicemix-camel</componentName>
  </properties>
</project>

服务单元的服务程序集的 Pom

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>aaa.bbb</groupId>
  <artifactId>theServiceAssembly</artifactId>
  <packaging>jbi-service-assembly</packaging>
  <version>0.0.1-SNAPSHOT</version>

  <parent>
    <groupId>aaa.bbb</groupId>
    <artifactId>theParent</artifactId>
    <version>1.0-SNAPSHOT</version>
    <relativePath>../pom.xml</relativePath>
  </parent>

  <dependencies>
    <dependency>
      <groupId>aaa.bbb</groupId>
      <artifactId>theServiceUnit</artifactId>
      <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.servicemix.tooling</groupId>
        <artifactId>jbi-maven-plugin</artifactId>
        <version>3.2.3</version>
        <extensions>true</extensions>
        <configuration>
          <type>service-assembly</type>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

【问题讨论】:

    标签: shared-libraries apache-servicemix jbi


    【解决方案1】:

    我认为您误解了 JBI Component/SharedLib/SA/SU 或类加载器的一些概念,JBI 的工作原理,请查看here 了解更多详细信息。

    我不明白你所说的“共享库服务单元 pom”是什么意思,根据 JBI 规范,SharedLib 不应该有任何服务单元,它只是由 JBI 组件引用,比如 servicemix-camel,所有servicemix JBI 组件只引用一个名为 servicemix-shared 的默认 SharedLib。

    类 org.apache.commons.dbcp.BasicDataSource 来自 commons-dbcp.jar 但 commons-dbcp.jar 不在 smx3.x 默认 sharedlib servicemix-shared-${version}-installer.zip 中,因此这意味着默认情况下所有 servicemix-camel su 都看不到此类,除非您在 SU 的 xbean.xml 中明确添加 &lt;library&gt;your_shared_lib_name&lt;/library&gt;

    【讨论】:

      猜你喜欢
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 2014-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多