如何使用jbi-maven-plugin集成servicemix共享库?
我使用 ServiceMix 3.5 我有多个 ServiceAssemblies,每个 ServiceAssemblies 对应一个 ServiceUnit。 服务单元有许多共同的库,因此我在 Maven pom 中将它们标记为范围“provided”。 共享库包含我希望服务单位共享的所有库。 我根据以下maven pom.xml构建,但效果是一个简单的例外:
java.lang.ClassNotFoundException: 类加载器中的 org.apache.commons.dbcp.BasicDataSource org.apache.xbean.spring.context.FileSystemXmlApplicationContext
我可以做什么(也许使用 jbi-maven-plugin)以便我的服务单元能够使用共享库中的 jar?
共享库服务单元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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您误解了 JBI Component/SharedLib/SA/SU 的一些概念或类加载器 JBI 的工作原理,请看一下 此处获取更多详细信息。
我无法理解“共享库服务单元 pom”的意思,因为根据 JBI 规范,SharedLib 不应该有任何服务单元,它只是由 JBI 组件引用,例如 servicemix-camel,所有 servicemix JBI 组件只引用一个默认的SharedLib,其名称为servicemix-shared。
org.apache.commons.dbcp.BasicDataSource 类来自 commons-dbcp.jar,但 commons-dbcp.jar 不在 smx3.x 默认共享库 servicemix-shared-${version}-installer.zip 中,所以这意味着默认情况下所有 servicemix-camel su 都看不到这个类,除非你明确添加SU 的 xbean.xml 中的
your_shared_lib_name
。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.