Linkage problem with Amazon AWS Java SDK and Grails

When trying the following snippet in a grails 1.3.5 app (you can test this through the console)... :

def ec2 = ctx.ec2Client
def rir = new RunInstancesRequest("<some-ami-id>", 1, 1)
Placement placement = new Placement()
RunInstancesResult result = ec2.runInstances(rir)

I get the following stack trace :

Exception thrown

java.lang.LinkageError: loader constraint violation: when resolving field "NODE" the class loader (instance of org/codehaus/groovy/grails/cli/support/GrailsRootLoader) of the referring class, javax/xml/xpath/XPathConstants, and the class loader (instance of <bootloader>) for the field's resolved type, javax/xml/namespace/QName, have different Class objects for that type
    at com.amazonaws.util.XpathUtils.asNode(
    at com.amazonaws.util.XpathUtils.evaluateAsString(
    at com.amazonaws.util.XpathUtils.asString(
    at com.amazonaws.transform.LegacyErrorUnmarshaller.parseErrorCode(
    at com.amazonaws.transform.LegacyErrorUnmarshaller.unmarshall(
    at com.amazonaws.transform.LegacyErrorUnmarshaller.unmarshall(
    at com.amazonaws.http.DefaultErrorResponseHandler.handle(
    at com.amazonaws.http.DefaultErrorResponseHandler.handle(
    at com.amazonaws.http.HttpClient.handleErrorResponse(
    at com.amazonaws.http.HttpClient.execute(

I have the following in my BuildConfig.groovy :

runtime 'com.amazonaws:aws-java-sdk:1.1.0'

Any idea of what could cause this ?


Solution : In BuildConfig.groovy, in the dependencies secion, add :

    excludes "stax-api"
    excludes "stax-api"

This is because both stax 1.2.0 and the amazon skd have a dependency on stax-api 1.0.1. In Java 1.6.0, the stax api is already bundled in the jre jars.

The accepted answer above did not work for me. I made the adjustment to my BuildConfig.groovy as indicated, but the error persisted.

Eventually I had to grep all my JAR files looking for javax/xml/namespace/QName and found that jaxrpc.jar in our custom in-house PayPal plugin had the errant class inclusion. The JAX-RPC library has since been updated and after I updated that JAR file (which no longer includes QName) it all worked fine.

So just mentioning it here in case the above solution doesn't work for others. If it doesn't, keep looking - somewhere there's a JAR file that includes QName, but shouldn't.

Need Your Help

Splitting A String into Multiple Values in SQL Server 2000

sql-server tsql sql-server-2000

I'm asking the question on behalf of someone that works for my client that asked me this. I'm actually more familiar with mySQL than SQL Server, but unfortunately, SQL Server is what the client has...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.