通过 IntelliJ 构建的 JAR 的"java.lang.ClassNotFoundException: software.amazon.awssdk.regions.Region"错误



我正在使用IntelliJ开发一个AWS应用程序(简单地从SecretsManager检索)。我能够在IntelliJ中运行应用程序,但是当我通过IntelliJ构建JAR工件并尝试执行JAR时,我得到java.lang.ClassNotFoundException: software.amazon.awssdk.regions.Region

我通过IntelliJ构建JAR,但我使用pom.xml来指定依赖项。当我尝试执行JAR时,我得到java.lang.ClassNotFoundException: software.amazon.awssdk.regions.Region错误。我已经将这个依赖项包含在pom.xml中,并且我还验证了JAR正在提取"software.amazon.awssdk. region"图书馆。

我不知道为什么JAR会抱怨"classnotfoundexception",而它正在寻找的类实际上就在JAR中?

任何指导是非常感谢!

我已经在下面包含了我的pom.xml:

<?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>com.chronoslabs</groupId>
<artifactId>chronos-trader</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>bom</artifactId>
<version>${aws.java.sdk.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.jmockit/jmockit -->
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.49</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.github.binance</groupId>
<artifactId>binance-connector-java</artifactId>
<version>1.12.0</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.9.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jmockit</groupId>
<artifactId>jmockit</artifactId>
<version>1.49</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.knowm.xchange/xchange-core -->
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-core</artifactId>
<version>5.0.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.knowm.xchange/xchange-stream-core -->
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-stream-core</artifactId>
<version>5.0.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.knowm.xchange/xchange-stream-service-netty -->
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-stream-service-netty</artifactId>
<version>5.0.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.knowm.xchange/xchange-binance -->
<dependency>
<groupId>org.knowm.xchange</groupId>
<artifactId>xchange-binance</artifactId>
<version>5.0.14</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<!-- https://logging.apache.org/log4j/2.x/manual/async.html -->
<dependency>
<groupId>com.lmax</groupId>
<artifactId>disruptor</artifactId>
<version>3.4.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/software.amazon.awssdk/secretsmanager -->
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>secretsmanager</artifactId>
<version>2.20.38</version>
</dependency>
<dependency>
<groupId>software.amazon.awssdk</groupId>
<artifactId>regions</artifactId>
<version>2.20.38</version>
<scope>provided</scope>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<aws.java.sdk.version>2.20.38</aws.java.sdk.version>
</properties>
</project>

最终帮助我的是maven-assembly-plugin。这将创建一个绑定了所有依赖项的JAR。

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>

相关内容

  • 没有找到相关文章

最新更新