How to integrate servicemix shared libraries using jbi-maven-plugin?

1.3k Views Asked by At

I use ServiceMix 3.5 I have multiple ServiceAssemblies, each one for a ServiceUnit. The service Units have in common many libraries, so i mark them in the maven pom with the scope 'provided'. The shared library contains all the libraries that i want the service units to share. I built according to the following maven pom.xml's but the effect is a simple exception:

java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource in classloader org.apache.xbean.spring.context.FileSystemXmlApplicationContext

What can i do (maybe using the jbi-maven-plugin) in order for my service units to make use of the jar's from the shared library?

Shared libraries service unit 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>

Shared libraries service unit 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 of the service unit that needs to use the shared libraries:

<?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 of the service assembly for the service unit

<?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>
1

There are 1 best solutions below

0
On

I think you misunderstand some concept of JBI Component/SharedLib/SA/SU or the classloader how JBI works, please take a look here to get more details.

I can't understand what you mean by "Shared libraries service unit pom", as in per JBI spec, the SharedLib shouldn't has any service unit, it just referred by the JBI component, like servicemix-camel, all servicemix JBI component only refer one default SharedLib which name is servicemix-shared.

Class org.apache.commons.dbcp.BasicDataSource is from commons-dbcp.jar but the commons-dbcp.jar isn't in the smx3.x default sharedlib servicemix-shared-${version}-installer.zip, so it means by default all servicemix-camel su can't see this class unless you explicitly add <library>your_shared_lib_name</library> in your SU's xbean.xml.