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

标签 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 有什么技巧吗?

最佳答案

尝试排除 stax-api:

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

仅仅引入 stax 就给了我:

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 )。

关于java - 来自 Groovy 脚本的 AWS Java SDK - 未找到提供程序 com.bea.xml.stream.MXParserFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44769904/

相关文章:

java - 使用 scene2d 在 libgdx 中居中选择框文本

amazon-web-services - 如何终止在远程 aws 服务器的端口中运行的进程

amazon-web-services - AWS CLI 可以与联合登录一起使用吗?

amazon-web-services - AWS : Boto3 configuring bucket lifecycle - Malformed XML

amazon-web-services - AWS SageMaker - 如何加载经过训练的 sklearn 模型以进行推理?

c# - 使用 Amazon API for .NET 设置内容编码和内容类型

java - PreparedStatement性能调优

java - FOR 循环中的 boolean 值

java - 使用java嵌入式密码查询获取节点的属性

java - AmazonS3ClientBuilder.defaultClient() 无法说明区域?