Add Apache Camel and Spring as jboss modules in WildFly

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

As Panagiotis suggests, 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:
<module xmlns="urn:jboss:module:1.3" name="org.springframework" slot="3.2.5.RELEASE">
  <resources>
    <resource-root path="aopalliance-1.0.jar"/>
    <resource-root path="aspectjrt-1.7.4.jar"/>
    <resource-root path="aspectjtools-1.7.4.jar"/>
    <resource-root path="aspectjweaver-1.7.4.jar"/>
    <resource-root path="org.aspectj.matcher-1.7.4.jar"/>
    <resource-root path="spring-aop-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-aspects-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-beans-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-context-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-context-support-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-core-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-expression-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-jdbc-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-orm-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-oxm-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-tx-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-web-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-webmvc-3.2.5.RELEASE.jar"/>
    <resource-root path="spring-webmvc-portlet-3.2.5.RELEASE.jar"/>
  </resources>

  <dependencies>
    <module name="javaee.api"/>
    <module name="org.apache.commons.logging"/>
    <module name="org.jboss.vfs"/>
    <module name="org.hibernate"/>
    <module name="javax.el.api" export="true"/>
    <module name="com.sun.xml.bind" export="true"/>
  </dependencies>
</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:
<module xmlns="urn:jboss:module:1.3" name="org.apache.camel" slot="2.12.1">
  <resources>
    <resource-root path="camel-core-2.12.1.jar"/>
    <resource-root path="camel-spring-2.12.1.jar"/>
    <resource-root path="jaxb-impl-2.2.6.jar"/>
  </resources>
  <dependencies>
    <module name="org.springframework" slot="3.2.5.RELEASE" />
    <module name="org.slf4j"/>
    <module name="javax.xml.bind.api"/>
    <module name="javax.api"/>
    <module name="sun.jdk" />
  </dependencies>
</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:

Caused by: java.lang.NoClassDefFoundError: sun/misc/Unsafe
    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentHashMapV8.getUnsafe(ConcurrentHashMapV8.java:4136) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentHashMapV8.<clinit>(ConcurrentHashMapV8.java:4101) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.<init>(ConcurrentLinkedHashMap.java:221) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap.<init>(ConcurrentLinkedHashMap.java:104) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.com.googlecode.concurrentlinkedhashmap.ConcurrentLinkedHashMap$Builder.build(ConcurrentLinkedHashMap.java:1634) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.util.LRUCache.<init>(LRUCache.java:83) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.util.LRUSoftCache.<init>(LRUSoftCache.java:68) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.impl.EndpointRegistry.<init>(EndpointRegistry.java:39) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.impl.DefaultCamelContext.<init>(DefaultCamelContext.java:234) [camel-core-2.12.1.jar:2.12.1]
    at org.apache.camel.spring.SpringCamelContext.<init>(SpringCamelContext.java:67) [camel-spring-2.12.1.jar:2.12.1]
    at org.apache.camel.spring.CamelContextFactoryBean.newCamelContext(CamelContextFactoryBean.java:356) [camel-spring-2.12.1.jar:2.12.1]
    at org.apache.camel.spring.CamelContextFactoryBean.createContext(CamelContextFactoryBean.java:350) [camel-spring-2.12.1.jar:2.12.1]
    at org.apache.camel.spring.CamelContextFactoryBean.getContext(CamelContextFactoryBean.java:361) [camel-spring-2.12.1.jar:2.12.1]
    at org.apache.camel.spring.CamelContextFactoryBean.getContext(CamelContextFactoryBean.java:80) [camel-spring-2.12.1.jar:2.12.1]
    at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.getContext(AbstractCamelContextFactoryBean.java:518) [camel-spring-2.12.1.jar:2.12.1]
    at org.apache.camel.core.xml.AbstractCamelContextFactoryBean.afterPropertiesSet(AbstractCamelContextFactoryBean.java:160) [camel-spring-2.12.1.jar:2.12.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509) [spring-beans-3.2.5.RELEASE.jar:3.2.5.RELEASE]
    ... 23 more
Caused 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))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
    ...

OR

Caused by: java.lang.NoClassDefFoundError: org/w3c/dom/Node
    at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_40]
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483) [rt.jar:1.7.0_40]
    at java.lang.Class.getConstructor0(Class.java:2793) [rt.jar:1.7.0_40]
    at java.lang.Class.getDeclaredConstructor(Class.java:2043) [rt.jar:1.7.0_40]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
    at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:129)
    ... 29 more
Caused 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))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
    ...

OR

Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException
    at java.lang.Class.getDeclaredConstructors0(Native Method) [rt.jar:1.7.0_40]
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2483) [rt.jar:1.7.0_40]
    at java.lang.Class.getConstructor0(Class.java:2793) [rt.jar:1.7.0_40]
    at java.lang.Class.getDeclaredConstructor(Class.java:2043) [rt.jar:1.7.0_40]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:105)
    at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:129)
    ... 29 more
Caused 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))]
    at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:197) [jboss-modules.jar:1.3.0.Final]
    ...

Hope it helps,
Adrianos Dadis.

Democracy Requires Free Software

About these ads

About Adrianos Dadis

Adrianos is working as senior software engineer in telcos business domain. Particularly interested in distributed systems, enterprise integration and middleware services. He mainly works with JBoss, Weblogic, Apache Storm, Apache HBase, Tomcat, Java EE, Spring, Drools, Oracle SOA Suite and various ESBs.
This entry was posted in Java, Java EE, JBoss, Software Development and tagged , , , . Bookmark the permalink.

Post your thought

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s