25 junho 2012

Maven Archetype: dynamic name for folders

Maven Archetypes are great! But some things lack documentation. If you are considering building your own archetypes, you may need this sooner or later.

I have a Maven Archetype to create modules for Apache Camel, and all of them will come up at the same ClassPath, but how to avoid conflicts when loading the Spring XML ApplicationContext? Put your XML files in different folders, or give them a different name.

I chose the first solution. If you want to give a folder a dynamic name, just call it __someProperty__ (yes, with double underscores). Think as you wanted to name the folder like ${artifactId}, but your operational system may not like this, so that's why Maven works with __artifactId__.

This is an example of my archetype.xml:

<?xml version="1.0" encoding="UTF-8"?>

And this is the project structure:

This is an archetype to load a Camel Context - with Spring - into JBoss 7.1.1 (as you may noticed from my previous posts) 


If you want to see more about this architecture, please let me know by +1 this post.

20 junho 2012

JBoss 7.1.1 and CXF WS Client

JBoss 7.1.1 has a slightly small bug that prevents one to use a WS Client (implemented on JBoss with Apache CXF). This issue has already been reported to the JBoss WS component and fixed on JBoss EAP 6.0.0 ER 5 (see this specific issue ticket).

This is the stack trace you may see on your server.log:

Caused by: java.lang.ClassNotFoundException: org.springframework.beans.BeansException from [Module "org.apache.cxf:main" from local module loader @15cda3f (roots: /opt/dev/servers/jboss-as-7.1.1.Final/modules)]
  at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423)
  at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
  at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120)
  ... 96 more

If you have JBoss EAP and a license, just update it. But if you are on JBoss 7.1.1, you have two options to workaround this problem:

  1. One is updating JBoss WS to the upcoming 4.1.0 release (still in beta and it seems it has not been released publicly).
  2. Your best option is to add a Spring module to your JBoss instance and then add a dependency on Spring to the CXF module:

How to add a Spring module to JBoss AS 7?

First thing to do is to choose the best version of Spring. Prefer the latest one (in the time of this writing, 3.1.1). But if your application is using 3.0.x, pick the latest version of this branch.
  1. On the jboss-as-7.1.1-Final folder, create this path:
    • modules/org/springframework/spring/main
      • on Unix, you can do this using $ mkdir -p <path>
  2. Add the following module.xml to this newly created folder
  3. Download these JARs and add them to this  newly created folder
  4. Open this file
    • jboss-as-7.1.1-Final/modules/org/apache/cxf/main/module.xml
  5. At the end of this file, make sure you have this module dependency:
    • <module name="org.springframework.spring" />
Restart your application server.

19 junho 2012

Issue with JBoss and Camel

If you are like me and are trying to run Apache Camel on JBoss 7.1.1, you may face an issue related to this exception:
Error description: You receive a stacktrace with an inner exception
on the form below.
Caused by: java.lang.NullPointerException
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.checkOverrideProperties(ClassBeanInfoImpl.java:205)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.<init>(ClassBeanInfoImpl.java:186)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:509)
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getOrCreate(JAXBContextImpl.java:528)
at com.sun.xml.bind.v2.runtime.property.ArrayReferenceNodeProperty.<init>(ArrayReferenceNodeProperty.java:87)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
[ ... and a looong intermediary stack trace removed ... The stacktrace
ends with: ]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:277)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:372)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:337)
at org.apache.camel.spring.handler.CamelNamespaceHandler.createJaxbContext
This happens because there's a bug on JAXB 2.2.4, the version used by default on JBoss 7.1.1.
I honestly don't know if this also happens to any other JBoss 7 versions, but this is a bug only with JAXB 2.2.4, so if the version you have has this JAXB version, you also have this problem.

To fix this, follow these instructions:

  1. Download the new version of JAXB (from Maven Repo)
    1. jaxb-impl-2.2.5-2
    2. jaxb-xjc-2.2.5-2
  2. Put these files on this JBoss folder:
    1. jboss-as-7.1.1.Final/modules/com/sun/xml/bind/main
  3. Open the file module.xml
    1. replace the old version (2.2.4) with the new one (2.2.5-2)
  4. Done!
Now get back to work!

PS: part of this solution (updating JAXB) is thanks to this thread.


LinkedIn: www.linkedin.com/in/brunocborges
Twitter: www.twitter.com/brunoborges
Comprei e Não Vou
Rio de Janeiro, RJ Brasil
São Paulo, SP Brasil