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)... :

import com.amazonaws.services.ec2.model.*
def ec2 = ctx.ec2Client
def rir = new RunInstancesRequest("<some-ami-id>", 1, 1)
Placement placement = new Placement()
placement.setGroupName("<yourPlacementGroup>")
rir.setPlacement(placement)
rir.setKeyName("<yourKeyPairName>")
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(XpathUtils.java:319)
    at com.amazonaws.util.XpathUtils.evaluateAsString(XpathUtils.java:363)
    at com.amazonaws.util.XpathUtils.asString(XpathUtils.java:120)
    at com.amazonaws.transform.LegacyErrorUnmarshaller.parseErrorCode(LegacyErrorUnmarshaller.java:96)
    at com.amazonaws.transform.LegacyErrorUnmarshaller.unmarshall(LegacyErrorUnmarshaller.java:62)
    at com.amazonaws.transform.LegacyErrorUnmarshaller.unmarshall(LegacyErrorUnmarshaller.java:29)
    at com.amazonaws.http.DefaultErrorResponseHandler.handle(DefaultErrorResponseHandler.java:76)
    at com.amazonaws.http.DefaultErrorResponseHandler.handle(DefaultErrorResponseHandler.java:36)
    at com.amazonaws.http.HttpClient.handleErrorResponse(HttpClient.java:508)
    at com.amazonaws.http.HttpClient.execute(HttpClient.java:215)
    at com.amazonaws.services.ec2.AmazonEC2Client.invoke(AmazonEC2Client.java:3804)
    at com.amazonaws.services.ec2.AmazonEC2Client.runInstances(AmazonEC2Client.java:267)
    at ConsoleScript2.run(ConsoleScript2:10)

I have the following in my BuildConfig.groovy :

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

Any idea of what could cause this ?

Answers


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

runtime('com.amazonaws:aws-java-sdk:1.1.0'){
    excludes "stax-api"
}
runtime('stax:stax:1.2.0'){
    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

maintaining ids in database that match client software enumerations

.net sql-server

Lets say I have a table in a sql server 2000 database called TransactionType:

problem at malloc

c malloc

i'm trying to apply malloc in my code, but still having a problem, there's an error saying : "request for member 'id' in something not a structure or union".

Android Activity switch loses fullscreen temporarily

android animation android-activity splash-screen

Can someone help me out here. I have a Splash screen as an Activity in my fullscreen App (landscape). When the Splash screen calls the main activity (with no animation) i lose fullscreen momentaril...

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.