来自Groovy脚本的AWS Java SDK - 找不到提供程序com.bea.xml.stream.MXParserFactory

时间:2017-06-26 23:04:06

标签: java amazon-web-services amazon-s3 groovy

我使用具有以下依赖关系的AWS Java S3 SDK。

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-s3</artifactId>
    <version>1.11.155</version>
</dependency>

Java的一切都很好用:

BasicAWSCredentials credentials = new BasicAWSCredentials(key, secret);
AmazonS3 s3 = AmazonS3ClientBuilder
   .standard()
   .withCredentials(new AWSStaticCredentialsProvider(credentials))
   .withRegion(region)
   .build();

如果我尝试通过Groovy脚本执行确切的操作:

def credentials = new BasicAWSCredentials(key, secret);
def s3 = AmazonS3ClientBuilder
   .standard()
   .withCredentials(new AWSStaticCredentialsProvider(credentials))
   .withRegion(s3region)
   .build()

我得到一个例外:

Caught: javax.xml.stream.FactoryConfigurationError: 
Provider com.bea.xml.stream.MXParserFactory not found

明确地将stax依赖项添加到我的.pom开始在其他地方给我冲突的类。

使用Groovy有一些技巧吗?

1 个答案:

答案 0 :(得分:0)

尝试排除stax-api:

@GrabConfig(systemClassLoader = true)
@Grab('stax:stax:1.2.0')
@GrabExclude('stax:stax-api')

拉进去只是给了我:

java.lang.LinkageError: loader constraint violation: when resolving field "DATETIME" the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the referring class, javax/xml/datatype/DatatypeConstants, and the class loader (instance of <bootloader>) for the field's resolved type, javax/xml/namespace/QName, have different Class objects for that type

stax-api依赖项的javax.xml.namespace.QName类与JRE(https://docs.oracle.com/javase/7/docs/api/javax/xml/namespace/QName.html)提供的类冲突。