线程“主”中的异常java.lang.NoSuchFieldError:JAVA_VENDOR

NyansusCoder:

当我尝试在AWS s3上创建存储桶时,出现以下错误:线程“ main”中的异常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)中。

我有openjdk 11;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)

mvn -version命令的结果:... Apache Maven 3.5.4 ...

这是我的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>

从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);
    }
}

我为赢得它System.setProperty("JAVA_VENDOR","Oracle Corporation");付出了一些努力:1)试试这个:,因为实际的系统属性具有中庸的“ 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)))

但是,JavaSystemSettings类中没有具有该名称的字段。我该如何处理?

TR; DR更新!它适用于我的下一个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>

斯蒂芬·C:

A NoSuchFieldError是由加载类时版本不匹配引起的。

(设置属性不能解决此问题。异常是指类的字段,而不是Properties对象中的属性。)

但是类中没有这样名称的字段JavaSystemSettings

究竟!包含UserAgentUtils该类的JAR与该类之间的版本不匹配JavaSystemSettings

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

线程“主”中的异常java.lang.NullPointerException1000

线程“主”中的异常java.lang.NoSuchMethodError:java.nio.ByteBuffer.flip()Ljava / nio / ByteBuffer

线程“主”中的异常java.lang.UnsupportedClassVersionError:

这在Java中-线程“主”中的异常java.lang.StackOverflowError

HTTPClient示例-线程“主”中的异常java.lang.NoSuchFieldError:INSTANCE

线程“主”中的异常java.lang.NoSuchFieldError:TRACE

线程“主”中的异常java.lang.IllegalMonitorStateException

线程“主”中的异常java.lang.UnsatisfiedLinkError:java.library.path中没有lwjgl

线程“主”中的异常java.lang.NoClassDefFoundError

线程“主”中的异常java.lang.NoSuchMethodError:主-如何解决该问题?

线程“主”中的异常java.lang.NullPointerException?

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException。为什么?

获取错误“线程“主”中的异常java.lang.ExceptionInInitializerError”

线程“主”中的java异常java.lang.NullPointerException错误

线程“主”中的异常java.lang.NoClassDefFoundError:org / apache / commons / lang / builder / CompareToBuilder

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:5错误

线程“主”中的异常java.lang.NoClassDefFoundError:scala / Cloneable

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:3

“线程“主”中的异常java.Lang.NullPointerException”错误

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:-33

Java泛型MergeSort,线程“主”中的异常java.lang.ClassCastException错误

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:10

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:4

线程“主”中的异常java.lang.StackOverflowError问题

PDFbox异常-线程“主”中的异常java.lang.VerifyError

neo4j线程“主”中的异常java.lang.OutOfMemoryError:Java堆空间

错误:线程“主”中的异常java.lang.NullPointerException

线程“主”中的异常java.lang.NoClassDefFoundError:rpc / Stub

线程“主”中的异常java.lang.ArrayIndexOutOfBoundsException:0