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 (i开发者_运维问答nstance 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 ?
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.
精彩评论