sanjbh
sanjbh

Reputation: 65

Groovy JsonBuilder classloading error in Wildfly-Camel 12

I am invoking JsonBuilder.toString() in Groovy code inside a Camel route. This Camel route runs inside Widlfly Camel 12.0. The code looks like so:

def builder = new JsonBuilder()
builder {
'myField': myFieldVal
}
return builder.toString()

The builder.toString() method invocation produces the following error:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class 
groovy.json.internal.FastStringUtils

But I do have the dependencies mentioned properly in pom.xml like so:

<dependency>
 <groupId>org.apache.camel</groupId>
 <artifactId>camel-groovy</artifactId>
 <scope>provided</scope>
</dependency>

I also tried adding this extra dependency to resolve the problem:

<dependency>
 <groupId>org.codehaus.groovy</groupId>
 <artifactId>groovy-json</artifactId>       
 <version>2.4.13</version>
</dependency>

But I still keep on getting the above exception. However when I run the same Camel code using the camel-maven-plugin, without deploying it inside Wildfly, it runs perfectly.

Can someone please help?

Thanks in advance.

Upvotes: 2

Views: 370

Answers (1)

James Netherton
James Netherton

Reputation: 1267

I think the problem is that module org.apache.camel.script.groovy cannot access sun.misc.Unsafe. So I added the following module dependency to modules/system/layers/fuse/org/apache/camel/script/groovy/main/module.xml.

<module name="sun.jdk">
  <imports>
    <include path="sun/misc/Unsafe"/>
  </imports>
</module>

Your example worked for me afterwards.

Upvotes: 2

Related Questions