paulwong

Add Apache Camel and Spring as jboss modules in WildFly

by  on November 29th, 2013 | Filed in: Enterprise Java Tags: 

These days I am playing with Wildfly and Apache Camel and Spring.

A simple way to communicate between EARs / WARs is using direct-vm component of Camel. There are many ways to achieve this with or without Camel. Camel works like a charm in WildFly without any need for extra configurations. Camel is great!!!

In order to avoid pack all required JARs of Spring and Camel with my applications, I create two modules, using the great JBoss Modules framework (which is already used by WildFly). Then I can reference these two frameworks, without the need to pack all these JARs inside my applications (EAR/WAR).
 

Create Spring module

  • Go to WildFly home dir: $> cd /home/torun/jboss/wildfly/wildfly-8.0.0.Beta1
  • Create Spring module directory structure:
    • $> mkdir -p modules/org/springframework/3.2.5.RELEASE
  • Inside this new directory, create module.xml file with this content:
01<module xmlns="urn:jboss:module:1.3" name="org.springframework" slot="3.2.5.RELEASE">
02  <resources>
03    <resource-root path="aopalliance-1.0.jar"/>
04    <resource-root path="aspectjrt-1.7.4.jar"/>
05    <resource-root path="aspectjtools-1.7.4.jar"/>
06    <resource-root path="aspectjweaver-1.7.4.jar"/>
07    <resource-root path="org.aspectj.matcher-1.7.4.jar"/>
08    <resource-root path="spring-aop-3.2.5.RELEASE.jar"/>
09    <resource-root path="spring-aspects-3.2.5.RELEASE.jar"/>
10    <resource-root path="spring-beans-3.2.5.RELEASE.jar"/>
11    <resource-root path="spring-context-3.2.5.RELEASE.jar"/>
12    <resource-root path="spring-context-support-3.2.5.RELEASE.jar"/>
13    <resource-root path="spring-core-3.2.5.RELEASE.jar"/>
14    <resource-root path="spring-expression-3.2.5.RELEASE.jar"/>
15    <resource-root path="spring-jdbc-3.2.5.RELEASE.jar"/>
16    <resource-root path="spring-orm-3.2.5.RELEASE.jar"/>
17    <resource-root path="spring-oxm-3.2.5.RELEASE.jar"/>
18    <resource-root path="spring-tx-3.2.5.RELEASE.jar"/>
19    <resource-root path="spring-web-3.2.5.RELEASE.jar"/>
20    <resource-root path="spring-webmvc-3.2.5.RELEASE.jar"/>
21    <resource-root path="spring-webmvc-portlet-3.2.5.RELEASE.jar"/>
22  </resources>
23 
24  <dependencies>
25    <module name="javaee.api"/>
26    <module name="org.apache.commons.logging"/>
27    <module name="org.jboss.vfs"/>
28    <module name="org.hibernate"/>
29    <module name="javax.el.api" export="true"/>
30    <module name="com.sun.xml.bind" export="true"/>
31  </dependencies>
32</module>
  • Then add all the JARs mentioned as “resource-root” inside this new directory
  • You are DONE with Spring module!!!
  • Now you can reference spring module using the next line in your “jboss-deployment-structure.xml”, from your EAR/WAR:
    • <module name=”org.springframework” slot=”3.2.5.RELEASE”/>

Create Camel module

  • Create Camel module directory structure:
    • $> mkdir -p modules/org/apache/camel/2.12.1
  • Inside this new directory, create module.xml file with this content:
01<module xmlns="urn:jboss:module:1.3" name="org.apache.camel" slot="2.12.1">
02  <resources>
03    <resource-root path="camel-core-2.12.1.jar"/>
04    <resource-root path="camel-spring-2.12.1.jar"/>
05    <resource-root path="jaxb-impl-2.2.6.jar"/>
06  </resources>
07  <dependencies>
08    <module name="org.springframework" slot="3.2.5.RELEASE" />
09    <module name="org.slf4j"/>
10    <module name="javax.xml.bind.api"/>
11    <module name="javax.api"/>
12    <module name="sun.jdk" />
13  </dependencies>
14</module>
  • Then add all the JARs mentioned as “resource-root” inside this new directory
  • You are DONE with Camel module!!!
  • Now you can reference camel module using the next line in your “jboss-deployment-structure.xml”, from your EAR/WAR:
    • <module name=”org.apache.camel” slot=”2.12.1″ />

You may cut out a few jar dependencies from Spring or Camel module, but these are just my current settings and I know it works!

One more important note. While I was trying to found the correct JARs for these modules, I met a few exceptions… So, if you forget any JAR, then you may see any of these exceptions:

01Caused by: java.lang.NoClassDefFoundError: sun/misc/Unsafe
02    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentHashMapV8.getUnsafe(ConcurrentHashMapV8.java:4136) [camel-core-2.12.1.jar:2.12.1]
03    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentHashMapV8.<clinit>(ConcurrentHashMapV8.java:4101) [camel-core-2.12.1.jar:2.12.1]
04    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.<init>(ConcurrentLinkedHashMap.java:221) [camel-core-2.12.1.jar:2.12.1]
05    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.<init>(ConcurrentLinkedHashMap.java:104) [camel-core-2.12.1.jar:2.12.1]
06    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.build(ConcurrentLinkedHashMap.java:1634) [camel-core-2.12.1.jar:2.12.1]
07    at org.apache.camel.util.LRUCache.<init>(LRUCache.java:83) [camel-core-2.12.1.jar:2.12.1]
08    at org.apache.camel.util.LRUSoftCache.<init>(LRUSoftCache.java:68) [camel-core-2.12.1.jar:2.12.1]
09    at org.apache.camel.impl.EndpointRegistry.<init>(EndpointRegistry.java:39) [camel-core-2.12.1.jar:2.12.1]
10    at org.apache.camel.impl.DefaultCamelContext.<init>(DefaultCamelContext.java:234) [camel-core-2.12.1.jar:2.12.1]
11    at org.apache.camel.spring.SpringCamelContext.<init>(SpringCamelContext.java:67) [camel-spring-2.12.1.jar:2.12.1]
12    at org.apache.camel.spring.CamelContextFactoryBean.newCamelContext(CamelContextFactoryBean.java:356) [camel-spring-2.12.1.jar:2.12.1]
13    at org.apache.camel.spring.CamelContextFactoryBean.createContext(CamelContextFactoryBean.java:350) [camel-spring-2.12.1.jar:2.12.1]
14    at org.apache.camel.spring.CamelContextFactoryBean.getContext(CamelContextFactoryBean.java:361) [camel-spring-2.12.1.jar:2.12.1]
15    at org.apache.camel.spring.CamelContextFactoryBean.getContext(CamelContextFactoryBean.java:80) [camel-spring-2.12.1.jar:2.12.1]
16    at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.getContext(AbstractCamelContextFactoryBean.java:518) [camel-spring-2.12.1.jar:2.12.1]
17    at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:160) [camel-spring-2.12.1.jar:2.12.1]
18    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
19    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
20    ... 23 more
21Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe from [Module "org.apache.camel:2.12.1" from local module loader @1a6e5d5 (finder: local module finder @3b3402 (roots: /home/torun/jboss/wildfly/wildfly-8.0.0.Beta1/modules,/home/torun/jboss/wildfly/wildfly-8.0.0.Beta1/modules/system/layers/base))]
22    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
23    ...

OR

01Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/Node
02    at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_40]
03    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483) [rt.jar:1.7.0_40]
04    at java.lang.Class.getConstructor0(Class.java:2793) [rt.jar:1.7.0_40]
05    at java.lang.Class.getDeclaredConstructor(Class.java:2043) [rt.jar:1.7.0_40]
06    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
07    at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:129)
08    ... 29 more
09Caused by: java.lang.ClassNotFoundException: org.w3c.dom.Node from [Module "org.apache.camel:2.12.1" from local module loader @1a6e5d5 (finder: local module finder @3b3402 (roots: /home/torun/jboss/wildfly/wildfly-8.0.0.Beta1/modules,/home/torun/jboss/wildfly/wildfly-8.0.0.Beta1/modules/system/layers/base))]
10    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
11    ...

OR

01Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
02    at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_40]
03    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483) [rt.jar:1.7.0_40]
04    at java.lang.Class.getConstructor0(Class.java:2793) [rt.jar:1.7.0_40]
05    at java.lang.Class.getDeclaredConstructor(Class.java:2043) [rt.jar:1.7.0_40]
06    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
07    at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:129)
08    ... 29 more
09Caused by: java.lang.ClassNotFoundException: javax.xml.bind.JAXBException from [Module "org.apache.camel:2.12.1" from local module loader @1a6e5d5 (finder: local module finder @3b3402 (roots: /home/torun/jboss/wildfly/wildfly-8.0.0.Beta1/modules,/home/torun/jboss/wildfly/wildfly-8.0.0.Beta1/modules/system/layers/base))]
10    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
11    ...

Hope it helps!

posted on 2015-02-21 20:13 paulwong 阅读(476) 评论(0)  编辑  收藏 所属分类: EJB3JBOSS


只有注册用户登录后才能发表评论。


网站导航: