Maven not running with Spigot

余生长醉 提交于 2021-01-28 17:10:00

问题


I'm trying to use MongoDB in a Spigot 1.16.1 Plugin and I'm having Problems with my maven imports.

In my IDE (EclipseIDE) there are no Errors. If I export the Plugin and reload the Server the following error appears:

pom.xml

<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>LeeCraft-Core_hj.2_v.2.0</groupId>
<artifactId>LeeCraft-Core_hj.2_v.2.0</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.mongodb</groupId>
        <artifactId>mongodb-driver-sync</artifactId>
        <version>4.1.0</version>
    </dependency>
</dependencies>

Main Class

package de.philipp.main;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;

import de.philipp.api.OnlineTimeAPI;
import de.philipp.data.Data;
import de.philipp.listener.JoinListener;
import de.philipp.mongodb.MongoDBHandler;
import de.philipp.mysql.MySQL;

public class Main extends JavaPlugin {

    @Override
    public void onDisable() {
    }

    @Override
    public void onEnable() {

        // MongoDB Connect
        
        MongoDBHandler.connect();


        // Start Plugin Message

        Bukkit.getConsoleSender().sendMessage("§b§l  _            §r§3 ___           __ _        _        ___               _    _      ___       _ _          ");
        Bukkit.getConsoleSender().sendMessage("§b§l | |   ___ ___ §r§3/ __|_ _ __ _ / _| |_   __| |___   / __|___ _ _ ___  (_)__| |_   / _ \\ _ _ | (_)_ _  ___ ");
        Bukkit.getConsoleSender().sendMessage("§b§l | |__/ -_) -_)§r§3 (__| '_/ _` |  _|  _|_/ _` / -_) | (__/ _ \\ '_/ -_) | (_-<  _| | (_) | ' \\| | | ' \\/ -_)");
        Bukkit.getConsoleSender().sendMessage("§b§l |____\\___\\__§r§3_|\\___|_| \\__,_|_|  \\__(_)__,_\\___|  \\___\\___/_| \\___| |_/__/\\__|  \\___/|_||_|_|_|_||_\\___|");
        Bukkit.getConsoleSender().sendMessage(" ");

        // Listener Register

        getServer().getPluginManager().registerEvents(new JoinListener(), this);

    }

}

I already tried to import the libary with a .jar file but that didn't worked too.

Any help is appreciated


回答1:


Use the Maven Shade Plugin to include the dependency in your jar.




回答2:


You should use the maven-assembly-plugin for creating a "fat" jarfile, example:

<plugins>
      <plugin>
        <!-- NOTE: We don't need a groupId specification because the group is
             org.apache.maven.plugins ...which is assumed by default.
         -->
        <artifactId>maven-assembly-plugin</artifactId>
        <version>3.3.0</version>
        <configuration>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
        [...]

This makes sure that every dependency with scope compile gets shaded into a jar file, it should be called (project name and version)-jar-with-dependencies.jar Note that you should set the scope of spigot to provided, because it is already loaded on runtime. Compile using mvn package.

PS: You should never import jars to the classpath using Idea/some other ide if you are using maven, import all your dependencies using Maven.



来源:https://stackoverflow.com/questions/63972961/maven-not-running-with-spigot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!