Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
“线程中的异常”;“主要”;java.lang.NoClassDefFoundError:使用控制台运行时。可能和Maven有关_Java_Maven_Netbeans_Command Line Interface - Fatal编程技术网

“线程中的异常”;“主要”;java.lang.NoClassDefFoundError:使用控制台运行时。可能和Maven有关

“线程中的异常”;“主要”;java.lang.NoClassDefFoundError:使用控制台运行时。可能和Maven有关,java,maven,netbeans,command-line-interface,Java,Maven,Netbeans,Command Line Interface,我有两个java文件: package com.pokebot; import javax.security.auth.login.LoginException; import net.dv8tion.jda.core.AccountType; import net.dv8tion.jda.core.JDA; import net.dv8tion.jda.core.JDABuilder; import net.dv8tion.jda.core.exceptions.RateLimitedExc

我有两个java文件:

package com.pokebot;

import javax.security.auth.login.LoginException;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.exceptions.RateLimitedException;

public class App {

    public static void main(String[] args)
    {
        try {
            JDA jdaBot = new JDABuilder(AccountType.BOT).setToken("my_token").buildBlocking();
            jdaBot.addEventListener(new Pokebot());
        } catch (LoginException e) {
    //            System.out.println("LoginException");
        } catch (InterruptedException e) {
    //            System.out.println("InterruptedException");
        } catch (RateLimitedException e) {
    //            System.out.println("RateLimitedException");
        }
    }

}
以及:

当我从Netbeans运行应用程序(主类是第一个文件中的App)时,我只收到一个通知:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
但该应用程序仍然有效。 当我尝试从命令行运行它时:

java -jar target/pokebotapp-1.0-SNAPSHOT.jar
然后我得到了这样一个例外:

线程“main”java.lang.NoClassDefFoundError中的异常:net/dv8tion/jda/core/exceptions/RateLimitedException

而且应用程序甚至没有启动

我正在使用Maven来完成这个项目。My 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.pokebot</groupId>
    <artifactId>pokebotapp</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <!--<classpathPrefix>lib/</classpathPrefix>-->
                            <mainClass>com.pokebot.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.5.1</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>
                                ${project.build.directory}/dependency-jars/
                            </outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>
    <dependencies>
        <dependency>
            <groupId>net.dv8tion</groupId>
            <artifactId>JDA</artifactId>
            <version>3.3.1_291</version>
        </dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>jcenter</id>
            <name>jcenter-bintray</name>
            <url>http://jcenter.bintray.com</url>
        </repository>
    </repositories>
    </project>

4.0.0
com.pokebot
口袋鼓
1.0-快照
罐子
org.apache.maven.plugins
maven jar插件
3.0.2
真的
com.pokebot.App
org.apache.maven.plugins
maven依赖插件
2.5.1
复制依赖项
包裹
复制依赖项
${project.build.directory}/dependency jars/
UTF-8
1.8
1.8
net.dv8tion
吉达
3.3.1_291
jcenter
jcenter垃圾箱
http://jcenter.bintray.com

在尝试从控制台运行项目之前,我先运行
maven compile
。我认为这可能是我运行程序的方式的错误,或者是我为这个项目设置maven的方式的错误。有人知道问题出在哪里吗?

这是因为java不知道从哪里获取这个libs。很少有选择:

  • 构建包含所有依赖项的jar(所谓的uber jar)。这是通过maven shade插件完成的。可在以下位置获取文档:

  • 做java-jar-cp吗 文件如下:

  • 第一个选项肯定更好:)我想应该有很多关于stackoverflow如何配置maven shade插件的例子。这样地:

    阅读本文,我为
    slf4j-api-1.7.5
    slf4j-simple-1.7.5
    添加了maven依赖项,但仍然存在相同的问题,即使在mvn clean安装之后,您是否更新了您的项目并检查了强制更新快照和版本?我尝试了
    mvn clean安装-U
    和Netbeans'
    下载声明的依赖项
    。。。还是一样。是否有其他方法更新项目?右键单击您的项目->Maven->更新项目->检查快照和版本的强制更新,然后单击确定添加Maven插件即可解决问题。谢谢:)
    Error: A JNI error has occurred, please check your installation and try again
    Exception in thread "main" java.lang.NoClassDefFoundError: net/dv8tion/jda/core/
    exceptions/RateLimitedException
            at java.lang.Class.getDeclaredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Unknown Source)
            at java.lang.Class.privateGetMethodRecursive(Unknown Source)
            at java.lang.Class.getMethod0(Unknown Source)
            at java.lang.Class.getMethod(Unknown Source)
            at sun.launcher.LauncherHelper.validateMainClass(Unknown Source)
            at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
    Caused by: java.lang.ClassNotFoundException: net.dv8tion.jda.core.exceptions.Rat
    eLimitedException
            at java.net.URLClassLoader.findClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
            at java.lang.ClassLoader.loadClass(Unknown Source)
            ... 7 more
    
    <?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.pokebot</groupId>
        <artifactId>pokebotapp</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>jar</packaging>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <addClasspath>true</addClasspath>
                                <!--<classpathPrefix>lib/</classpathPrefix>-->
                                <mainClass>com.pokebot.App</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <version>2.5.1</version>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <outputDirectory>
                                    ${project.build.directory}/dependency-jars/
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <maven.compiler.source>1.8</maven.compiler.source>
            <maven.compiler.target>1.8</maven.compiler.target>
        </properties>
        <dependencies>
            <dependency>
                <groupId>net.dv8tion</groupId>
                <artifactId>JDA</artifactId>
                <version>3.3.1_291</version>
            </dependency>
        </dependencies>
        <repositories>
            <repository>
                <id>jcenter</id>
                <name>jcenter-bintray</name>
                <url>http://jcenter.bintray.com</url>
            </repository>
        </repositories>
        </project>