[英]SLF4J .NoClassDefFoundError when running by command line on jar file
I have an app that runs well if I start it using the Intellij button after a mvn clean install (all using the GUI).如果我在 mvn clean install(全部使用 GUI)之后使用 Intellij 按钮启动它,我有一个运行良好的应用程序。
I try to run the generated jar file using the command line:我尝试使用命令行运行生成的 jar 文件:
java -jar myJar.jar
But I can't stop running into these errors:但我不能停止遇到这些错误:
java -jar .\myJar-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at data.SecretProvider.<clinit>(SecretProvider.java:14)
Again, if I run the app using Intellij, no errors and the logs work.同样,如果我使用 Intellij 运行应用程序,则不会出现错误并且日志可以正常工作。
I think it's the way I package my jar in the pom.xml, but I have very to no knowledge about it.我认为这是我在 pom.xml 中的 package 我的 jar 的方式,但我对此一无所知。 Here's the pom.xml
这是 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>org.bouji</groupId>
<artifactId>myjar</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>5.0.0-alpha.3</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.77</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.163</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jool</artifactId>
<version>0.9.14</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.960</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<!-- Build an executable JAR -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<archive>
<manifest>
<mainClass>CatBot</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Tried reading similar issues on here, but it seems to always be specific to the error/ide.尝试在这里阅读类似的问题,但它似乎总是特定于错误/ide。
In jar's MANIFEST file there must be dependencies that needed for the application to run.在 jar 的 MANIFEST 文件中,必须有应用程序运行所需的依赖项。 Ensure that you have them.
确保您拥有它们。
Also -jar
doesn't include classpath other than file itself.此外
-jar
不包括文件本身以外的类路径。 You can try to run with:您可以尝试运行:
java -cp <path>myJar-SNAPSHOT.jar;<path to missing> <your main class>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.