Solved Trying to add HikariCP in Maven (ECLIPSE IDE)

Discussion in 'Spigot Plugin Development' started by HotDoctor, Dec 8, 2019.

Thread Status:
Not open for further replies.
  1. Well first of all I want to say that I'ts my first time using maven.
    I've already read some threads on forums but i can get a solution (atleast for me)

    This is my pom.xml:
    Code (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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>MySQLPAPIBridge</groupId>
      <artifactId>MySQLPAPIBridge</artifactId>
      <version>1.0</version>
      <name>MySQLPAPIBridge</name>
          <repositories>
            <repository>
              <id>spigot-repo</id>
              <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>placeholderapi</id>
                <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
            </repository>
        </repositories>
        <dependencies>
            <dependency>
              <groupId>com.zaxxer</groupId>
              <artifactId>HikariCP</artifactId>
               <version>3.4.1</version>
               <scope>compile</scope>
            </dependency>
            <dependency>
              <groupId>org.spigotmc</groupId>
              <artifactId>spigot-api</artifactId>
              <version>1.14.4-R0.1-SNAPSHOT</version>
              <scope>provided</scope>
            </dependency>
            <dependency>
             <groupId>me.clip</groupId>
              <artifactId>placeholderapi</artifactId>
              <version>LATEST</version>
             <scope>provided</scope>
            </dependency>
        </dependencies>
      <build>
        <defaultGoal>clean compile assembly:single</defaultGoal>
        <sourceDirectory>src</sourceDirectory>
        <plugins>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
           </plugin>
           <plugin>
              <artifactId>maven-assembly-plugin</artifactId>
              <configuration>
                <archive>
                  <manifest>
                    <mainClass>
                      hotdoctor.plugin.mysqlpapibridge.Main
                    </mainClass>
                  </manifest>
                </archive>
                <descriptorRefs>
                  <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
              </configuration>
            </plugin>
          </plugins>
      </build>
      <properties>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>
      </properties>
    </project>
     
    I have no errors in console (of Eclipse) but when I go to use my plugin it says:
    Code (Java):

     java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariDataSource
     
    Any help I would appreciate it, Thanks alot.
     
  2. you need to shade it with maven shade plugin https://maven.apache.org/plugins/maven-shade-plugin/
     
    • Friendly Friendly x 1
  3. Im sorry but i just cant
    this is my new pom.xml
    Code (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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>MySQLPAPIBridge</groupId>
      <artifactId>MySQLPAPIBridge</artifactId>
      <version>1.0</version>
      <name>MySQLPAPIBridge</name>
          <repositories>
            <repository>
              <id>spigot-repo</id>
              <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>placeholderapi</id>
                <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
            </repository>
        </repositories>
        <dependencies>
            <dependency>
              <groupId>com.zaxxer</groupId>
              <artifactId>HikariCP</artifactId>
               <version>3.4.1</version>
               <scope>compile</scope>
            </dependency>
            <dependency>
              <groupId>org.spigotmc</groupId>
              <artifactId>spigot-api</artifactId>
              <version>1.14.4-R0.1-SNAPSHOT</version>
              <scope>provided</scope>
            </dependency>
            <dependency>
             <groupId>me.clip</groupId>
              <artifactId>placeholderapi</artifactId>
              <version>LATEST</version>
             <scope>provided</scope>
            </dependency>
        </dependencies>
      <build>
            <defaultGoal>clean package</defaultGoal>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>3.1.0</version>
                    <configuration>
                        <!-- put your configurations here -->
                    </configuration>
                    <executions>

                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            <resources>
                <resource>
                    <directory>MySQLPAPIBridge/src</directory>
                    <filtering>true</filtering>
                </resource>
            </resources>

      </build>
    </project>
     
     
  4. Looks fine to me. Paste your maven output when you build.
     
  5. do I have to paste my maven output in the folder target right?
     
  6. He means the console log I guess.
     
  7. Nevermind, I got it work
    but i have this problem when I load my plugin:
    Code (Java):

    [11:21:17 WARN]: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
    [11:21:17 WARN]: SLF4J: Defaulting to no-operation (NOP) logger implementation
    [11:21:17 WARN]: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
     
     
  8. This is my pom.xml
    Code (XML):

            <properties>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          </properties>
            <repositories>
            <repository>
                <id>mvnrepository</id>
                <url>http://mvnrepository.com/artifact</url>
            </repository>
            <repository>
              <id>spigot-repo</id>
              <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>placeholderapi</id>
                <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
            </repository>
        </repositories>
          <dependencies>
         
            <dependency>
              <groupId>com.zaxxer</groupId>
              <artifactId>HikariCP</artifactId>
               <version>3.4.1</version>
               <scope>compile</scope>
               <type>jar</type>
            </dependency>
            <dependency>
              <groupId>org.spigotmc</groupId>
              <artifactId>spigot-api</artifactId>
              <version>1.14.4-R0.1-SNAPSHOT</version>
              <scope>provided</scope>
            </dependency>
           <dependency>
             <groupId>me.clip</groupId>
              <artifactId>placeholderapi</artifactId>
              <version>2.10.4</version>
             <scope>provided</scope>
           </dependency>
              <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>1.7.25</version>
                <scope>compile</scope>
                <type>jar</type>
            </dependency>
          </dependencies>
         
      <build>
      <defaultGoal>package</defaultGoal>
      <finalName>${project.name}</finalName>
        <sourceDirectory>${basedir}/src/</sourceDirectory>
             <resources>
             <resource>
                   <directory>src/main/resources</directory>
                    <filtering>false</filtering>
             </resource>
            </resources>
        <plugins>
          <plugin>
           <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.1</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.3.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.4.3</version>
                  <configuration>
                      <artifactSet>
                          <includes>
                              <include>com.zaxxer:*:*:*</include>
                              <include>org.slf4j:*:*:*</include>
                          </includes>
                      </artifactSet>
                  </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
          <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
            <configuration>
              <source>1.8</source>
              <target>1.8</target>
            </configuration>
          </plugin>
        </plugins>
      </build>
     
     
  9. Nevermind, I got it work

    For players with this issue, this is my new pom.xml:
    Code (XML):

            <properties>
              <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
          </properties>
            <repositories>
            <repository>
                <id>mvnrepository</id>
                <url>http://mvnrepository.com/artifact</url>
            </repository>
            <repository>
              <id>spigot-repo</id>
              <url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
            </repository>
            <repository>
                <id>placeholderapi</id>
                <url>http://repo.extendedclip.com/content/repositories/placeholderapi/</url>
            </repository>
        </repositories>
          <dependencies>
         
            <dependency>
              <groupId>com.zaxxer</groupId>
              <artifactId>HikariCP</artifactId>
               <version>3.4.1</version>
               <scope>compile</scope>
               <type>jar</type>
            </dependency>
            <dependency>
              <groupId>org.spigotmc</groupId>
              <artifactId>spigot-api</artifactId>
              <version>1.14.4-R0.1-SNAPSHOT</version>
              <scope>provided</scope>
            </dependency>
           <dependency>
             <groupId>me.clip</groupId>
              <artifactId>placeholderapi</artifactId>
              <version>2.10.4</version>
             <scope>provided</scope>
           </dependency>
              <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-jdk14</artifactId>
                <version>1.7.25</version>
                <scope>compile</scope>
                <type>jar</type>
            </dependency>
          </dependencies>
         
      <build>
      <defaultGoal>package</defaultGoal>
      <finalName>${project.name}</finalName>
        <sourceDirectory>${basedir}/src/</sourceDirectory>
             <resources>
                <resource>
                    <targetPath>.</targetPath>
                    <filtering>true</filtering>
                    <directory>${basedir}/</directory>
                    <includes>
                        <include>plugin.yml</include>
                        <include>config.yml</include>
                    </includes>
                </resource>
            </resources>
        <plugins>
          <plugin>
           <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.8.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                  <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>2.3.1</version>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.4.3</version>
                  <configuration>
                      <artifactSet>
                          <includes>
                              <include>com.zaxxer:*:*:*</include>
                              <include>org.slf4j:*:*:*</include>
                          </includes>
                      </artifactSet>
                  </configuration>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
        </plugins>
      </build>
    </project>
     
     
Thread Status:
Not open for further replies.