ERROR - Uncaught Error: java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariDataSource

2,805 views
Skip to first unread message

Ouizzo

unread,
May 26, 2015, 5:56:09 AM5/26/15
to hika...@googlegroups.com
Hi!


Im getting this error, when running my program :

ERROR - Uncaught Error:
java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariDataSource
at java.lang.Class.getDeclaredMethods0(Native Method)
Caused by: java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariDataSource
at java.net.URLClassLoader$1.run(Unknown Source)

 and have try for a while now to figure it out. Can you please help me in some way!

My pom:
<?xml version="1.0" encoding="UTF-8"?>
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dcsquare.hivemq</groupId>
    <artifactId>hivemq-database-example-plugin</artifactId>
    <version>1.0-SNAPSHOT</version>


    <inceptionYear>2014</inceptionYear>
    <organization>
        <name>dc-square GmbH</name>
        <url>http://www.dc-square.de</url>
    </organization>

    <developers>
        <developer>
            <id>dobermai</id>
            <organization>dc-square GmbH</organization>
            <organizationUrl>http://www.dc-square.de</organizationUrl>
        </developer>
    </developers>


    <dependencies>
        <dependency>
            <groupId>com.hivemq</groupId>
            <artifactId>hivemq-spi</artifactId>
            <version>2.0.0</version>
        </dependency>
        <!-- Database dependencies -->
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>1.3.8</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.31</version>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</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>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <artifactSet>
                                <excludes>
                                    <exclude>com.dcsquare.hivemq:hivemq-spi</exclude>
                                    <exclude>com.google.inject:*</exclude>
                                    <exclude>com.google.guava:*</exclude>
                                    <exclude>org.slf4j:*</exclude>
                                    <exclude>ch.qos.logback:*</exclude>
                                </excludes>
                            </artifactSet>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <profiles>
        <profile>
            <id>RunWithHiveMQ</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.dcsquare</groupId>
                        <artifactId>hivemq-maven-plugin</artifactId>
                        <version>1.0.0</version>
                        <executions>
                            <execution>
                                <id>hivemq</id>
                                <phase>package</phase>
                                <goals>
                                    <goal>hivemq</goal>
                                </goals>
                                <configuration>
                                    <debugMode>SERVER</debugMode>
                                    <hiveMQDir>C:\hivemq-2.3.1</hiveMQDir>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>


    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
        </license>
    </licenses>


    <repositories>
        <repository>
            <id>repository.hivemq.com</id>
            <name>HiveMQ Repository</name>
            <releases>
            </releases>
            <snapshots>
            </snapshots>
        </repository>
    </repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>repository.hivemq.com</id>
            <name>HiveMQ Repository</name>
            <releases>
            </releases>
            <snapshots>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>


</project>

The main java file:

package com.dcsquare.hivemq.example.database;

import com.dcsquare.hivemq.spi.HiveMQPluginModule;
import com.dcsquare.hivemq.spi.PluginEntryPoint;
import com.dcsquare.hivemq.spi.plugin.meta.Information;
import com.google.inject.Provider;
import com.google.inject.Provides;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.configuration.AbstractConfiguration;

import javax.inject.Singleton;
import java.sql.Connection;
import java.sql.SQLException;

import static com.dcsquare.hivemq.spi.config.Configurations.noConfigurationNeeded;

/**
 *
 */
@Information(
        name = "Database Example Plugin",
        version = "1.0-SNAPSHOT",
        author = "dc-square GmbH",
        description = "A example plugin which persists every message to the database and authenticates clients from the database")
public class DatabaseExamplePluginModule extends HiveMQPluginModule {


    @Provides
    public Connection provideConnection(final HikariDataSource ds) throws SQLException {
        return ds.getConnection();
    }

    @Provides
    @Singleton
    public HikariDataSource provideConnectionPool() {


        final HikariConfig config = new HikariConfig();
        config.setMaximumPoolSize(15);
        config.setDataSourceClassName("com.mysql.jdbc.jdbc2.optional.MysqlDataSource");
        config.addDataSourceProperty("serverName", "localhost");
        config.addDataSourceProperty("port", "3306");
        config.addDataSourceProperty("databaseName", "newdatabase");
        config.addDataSourceProperty("user", "root");
        config.addDataSourceProperty("password", "Beer");


        config.addDataSourceProperty("cachePrepStmts", true);
        config.addDataSourceProperty("prepStmtCacheSize", 250);
        config.addDataSourceProperty("useServerPrepStmts", true);

        return new HikariDataSource(config);

    }

    @Override
    public Provider<Iterable<? extends AbstractConfiguration>> getConfigurations() {
        //You probably want an external file configuration
        return noConfigurationNeeded();
    }

    @Override
    protected void configurePlugin() {
    }

    @Override
    protected Class<? extends PluginEntryPoint> entryPointClass() {
        return DatabaseExamplePlugin.class;
    }
}


regards
Ouizzo

Brett Wooldridge

unread,
May 26, 2015, 10:33:19 AM5/26/15
to hika...@googlegroups.com, niclas...@gmail.com
At least try HikariCP 2.3.8.  HikariCP 1.3.8 is a year old.  Beyond that, it looks like a classpath issue more than anything.

-Brett

Ouizzo

unread,
May 26, 2015, 10:40:29 AM5/26/15
to hika...@googlegroups.com, niclas...@gmail.com
Ok, thanks!

Im compiling with jdk1.7

Should I use  <artifactId>HikariCP-java6</artifactId> or just  <artifactId>HikariCP</artifactId> in pom?

Is it the classpath for Eclipse, or do it concern any other claspath settings?

regards
Ouizzo

Brett Wooldridge

unread,
May 26, 2015, 10:43:07 AM5/26/15
to hika...@googlegroups.com, niclas...@gmail.com
If Jdk 1.7 then you need to HikariCP-java6 artifact.  In Eclipse, if you are using the m2e plugin and importing the pom.xml as a Maven Project, I believe it should manage the classpath properly.

-Brett

Ouizzo

unread,
May 26, 2015, 10:49:22 AM5/26/15
to hika...@googlegroups.com, niclas...@gmail.com
Ok, then I go with that! You can se my dataconnection in above code, can u see if there anything wrong with it? Do I have to make any changes in the pom for make it work. Im asking becouse when I run the build project in a broker (small server) as a plugin prog. I get the error. 

regards
Ouizzo

Brett Wooldridge

unread,
May 26, 2015, 10:53:05 AM5/26/15
to hika...@googlegroups.com, niclas...@gmail.com
DataSource properties look fine to me.  I'm not sure about the pom in general, that question is probably best asked on Stackoverflow.com.

-Brett

Ouizzo

unread,
May 26, 2015, 11:07:23 AM5/26/15
to hika...@googlegroups.com, niclas...@gmail.com
Ok, sorry for I got so many questions right now! 

But when I "run as 4 maven build".. And run it in server mode (which is like you run the server in Eclipse). Then I get this message:

[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output

INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing C:\hivemq-2.3.1\plugins\hivemq-database-example-plugin-master\target\hivemq-database-example-plugin-1.0-SNAPSHOT.jar with C:\hivemq-2.3.1\plugins\hivemq-database-example-plugin-master\target\hivemq-database-example-plugin-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: C:\hivemq-2.3.1\plugins\hivemq-database-example-plugin-master\dependency-reduced-pom.xml
[INFO] 
[INFO] --- hivemq-maven-plugin:1.0.0:hivemq (hivemq) @ hivemq-database-example-plugin ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 9.420 s
[INFO] Finished at: 2015-05-26T16:57:32+01:00
[INFO] Final Memory: 12M/184M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.dcsquare:hivemq-maven-plugin:1.0.0:hivemq (hivemq) on project hivemq-database-example-plugin: An error occured while deleting C:\hivemq-2.3.1\plugins\hivemq-database-example-plugin-master\target\debug: Unable to delete file: C:\hivemq-2.3.1\plugins\hivemq-database-example-plugin-master\target\debug\hivemq-database-example-plugin-1.0-SNAPSHOT.jar -> [Help 1]

And in the broker, this error will be shown:

1) A binding to java.sql.Connection was already configured at com.dcsquare.hivemq.example.database.DatabaseExamplePluginModule.provideConnection().
  at com.dcsquare.hivemq.example.database.DatabaseExamplePluginModule.provideConnection(DatabaseExamplePluginModule.java:31)

My question is, is the classpath set now and there is just a binding problem.. ? 
Reply all
Reply to author
Forward
0 new messages