HikariCP with spigot not importing with the JAR

Discussion in 'Spigot Plugin Development' started by Nukreeper64, Jun 10, 2017.

  1. I tried to follow this tutorial for implementing HikariCP with SQL. This was my first time using maven to handle dependencies. At first it seemed to be working fine. The spigot-api and spigot server jars automatically imported into the project and my IDE seems to think I have the Hikari classes available. however when I export the project as a plugin and run it on my server it gives me a noClassDefFoundError.

    The stack trace:
    Code (Text):

    [19:47:40 ERROR]: Error occurred while enabling [my_plugin_here] v0.1 (Is it up to date?)
    java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariDataSource
      at org.nukreeper64.[my_plugin_here].SQL.<init>(SQL.java:23) ~[?:?]
      at org.nukreeper64.[my_plugin_here].Main.onEnable(Main.java:74) ~[?:?]
      at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:264) ~[spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:402) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugin(CraftServer.java:377) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.enablePlugins(CraftServer.java:327) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.reload(CraftServer.java:748) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.Bukkit.reload(Bukkit.java:525) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchCommand(CraftServer.java:644) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.craftbukkit.v1_12_R1.CraftServer.dispatchServerCommand(CraftServer.java:630) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at net.minecraft.server.v1_12_R1.DedicatedServer.aP(DedicatedServer.java:443) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at java.lang.Thread.run(Unknown Source) [?:1.8.0_101]
    Caused by: java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariDataSource
      at java.net.URLClassLoader.findClass(Unknown Source) ~[?:1.8.0_101]
      at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:101) ~[spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86) ~[spigot-1.12.jar:git-Spigot-d5dfb24-ed8c725]
      at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_101]
      at java.lang.ClassLoader.loadClass(Unknown Source) ~[?:1.8.0_101]
      ... 18 more
     
    my pom.xml: (auto-generated by eclipse)
    Code (Text):

    <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.nukreeper64</groupId>
      <artifactId>plasmoCraft</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <packaging>jar</packaging>

      <name>plasmoCraft</name>
      <url>http://maven.apache.org</url>

      <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      </properties>

      <dependencies>
      <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
      </dependency>
      <dependency>
         <groupId>org.spigotmc</groupId>
         <artifactId>spigot-api</artifactId>
         <version>1.12-R0.1-SNAPSHOT</version>
      </dependency>
      <dependency>
         <groupId>org.spigotmc</groupId>
         <artifactId>spigot</artifactId>
         <version>1.12-R0.1-SNAPSHOT</version>
      </dependency>
      <dependency>
         <groupId>com.zaxxer</groupId>
         <artifactId>HikariCP</artifactId>
         <version>2.6.1</version>
      </dependency>
      <dependency>
         <groupId>org.apache.commons</groupId>
         <artifactId>commons-io</artifactId>
         <version>1.3.2</version>
      </dependency>
      </dependencies>
    </project>

     
     
  2. I use this in my pom file to add the dependencies into the jar file
    Code (Text):
        <build>
            <finalName>${project.name}</finalName>
            <defaultGoal>clean package</defaultGoal>

            <resources>
                <resource>
                    <directory>src/main/resources</directory>
                    <filtering>true</filtering>

                    <includes>
                        <include>*</include>
                    </includes>
                </resource>
            </resources>

            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.5.1</version>

                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.4.3</version>

                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>

                    <configuration>
                        <createDependencyReducedPom>false</createDependencyReducedPom>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    Then you will have to run it using maven with the command "clean package"
     
  3. @nokoa I was using "clean verify" before. Some other resource on maven said to use that. I switched it to "clean package", ran it as maven build, and exported the project. There is no difference in the stacktrace I get.
     
  4. @nokoa I also tried the additional lines you posted for my pom.xml. It looked like it was going to work. In the eclipse console, it said it was "Including com.zaxxer:HikariCP:jar:2.6.1 in the shaded jar", but when I exported the jar, it was still the same error. And there is no reference to hikari inside the exported jar that I can find.
     
  5. When you run maven it builds the jar for you and saves it in the target directory of the project, you don't need to re export the jar.
     
  6. @nokoa Cool. That worked. How do I get it to include my plugin.yml and other files? Or do I just have to drag them into the jar file manually?