[英]Exception in thread “main” java.lang.NoSuchFieldError: JAVA_VENDOR
When I try to create bucket at aws s3, get this error: Exception in thread "main" java.lang.NoSuchFieldError: JAVA_VENDOR at software.amazon.awssdk.core.internal.util.UserAgentUtils.userAgent(UserAgentUtils.java:87) at software.amazon.awssdk.core.internal.util.UserAgentUtils.initializeUserAgent(UserAgentUtils.java:73). 当我尝试在AWS s3上创建存储桶时,出现以下错误: 线程“主”中的异常java.lang.NoSuchFieldError:software.amazon.awssdk.core.internal.util.UserAgentUtils.userAgent(UserAgentUtils.java:87)上的JAVA_VENDOR在software.amazon.awssdk.core.internal.util.UserAgentUtils.initializeUserAgent(UserAgentUtils.java:73)中。
I have openjdk 11; 我有openjdk 11; results of java -version command java -version命令的结果
openjdk version "11.0.1" 2018-10-16
OpenJDK Runtime Environment 18.9 (build 11.0.1+13)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.1+13, mixed mode)
Result of mvn -version command: ... Apache Maven 3.5.4 ... mvn -version命令的结果:... Apache Maven 3.5.4 ...
This is my pom file: 这是我的pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>c</groupId>
<artifactId>e</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.5.19</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>regions</artifactId>
<version>2.5.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-nop -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Simple create bucket example from aws: 从aws创建一个简单的bucket示例:
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.CreateBucketConfiguration;
import software.amazon.awssdk.services.s3.model.CreateBucketRequest;
public class Main {
public static void main(String[] args) {
System.setProperty("JAVA_VENDOR","Oracle Corporation");
Region region = Region.US_WEST_2;
S3Client s3 = S3Client.builder().region(region).build();
String bucket = "bucket" + System.currentTimeMillis();
CreateBucketRequest createBucketRequest = CreateBucketRequest
.builder()
.bucket(bucket)
.createBucketConfiguration(CreateBucketConfiguration.builder()
.locationConstraint(region.id())
.build())
.build();
s3.createBucket(createBucketRequest);
}
}
I made some efforts to win it: 1) try this : System.setProperty("JAVA_VENDOR","Oracle Corporation");
我为赢得它System.setProperty("JAVA_VENDOR","Oracle Corporation");
了一些努力:1)试试: System.setProperty("JAVA_VENDOR","Oracle Corporation");
, because the real system property has nave "java.vendor" 2) I found problem place in at software.amazon.awssdk.core.internal.util.UserAgentUtils.userAgent: it calls JAVA_VENDOR from software.amazon.awssdk.utils.JavaSystemSettings ,因为实际系统属性具有中庸的“ java.vendor” 2)我在software.amazon.awssdk.core.internal.util.UserAgentUtils.userAgent中发现了问题所在:它从software.amazon.awssdk.utils.JavaSystemSettings调用JAVA_VENDOR
.replace("{java.vendor}", sanitizeInput(JavaSystemSetting.JAVA_VENDOR.getStringValue().orElse(null)))
But there is no field with such name in the JavaSystemSettings class. 但是,JavaSystemSettings类中没有具有该名称的字段。 How can i handle it? 我该如何处理?
TR; TR; DR UPDATE! DR更新! It work for me with next maven pom file: 它适用于我的下一个maven pom文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>c</groupId>
<artifactId>e</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>sdk-core</artifactId>
<version>2.5.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/s3 -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>s3</artifactId>
<version>2.5.19</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/regions -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>regions</artifactId>
<version>2.5.19</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>2.5.19</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
A NoSuchFieldError
is caused by a version mismatch when loading a class. NoSuchFieldError
是由加载类时版本不匹配引起的。
(Setting properties won't fix this. The exception refers to a field of a class, not a property in a Properties
object.) (设置属性不能解决此问题。异常是指类的字段,而不是Properties
对象中的Properties
。)
But there is no field with such name in the
JavaSystemSettings
class. 但是,JavaSystemSettings
类中没有具有该名称的JavaSystemSettings
。
Exactly! 究竟! You have a version mismatch between JARs containing the UserAgentUtils
class and the JavaSystemSettings
class. 包含UserAgentUtils
类和JavaSystemSettings
类的JAR之间版本不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.