Adrianos Dadis

About Adrianos Dadis

Adrianos is working as senior software engineer in telcos business domain. Particularly interested in enterprise integration, multi-tier architecture and middleware services. He mainly works with Weblogic, JBoss, Java EE, Spring, Drools, Oracle SOA Suite and various ESBs.

Add Apache Camel and Spring as jboss modules in WildFly

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:
<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!
 

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

One Response to "Add Apache Camel and Spring as jboss modules in WildFly"

  1. Michael says:

    Are you still able to make this work in version 8.1 of Wildfly? I keep getting;

    Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/context]

    The required files are all there.

Leave a Reply


6 × nine =



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close