WarWolfen
WarWolfen

Reputation: 241

HikariCP is not found when running the jar

In a project, we are using Hibernate with HikariCP and it all works fine in Eclipse. But as soon as I generate a jar file (Maven), hikaricp cannot be found anymore. I have turned this in every possible angle, but I cannot figure out what is wrong...

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
 version="2.0">
    <persistence-unit name="starmap" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>net.clanwolf.c3.transfer.pojos.User</class>
        <class>net.clanwolf.c3.transfer.pojos.RolePlayStory</class>
        <class>net.clanwolf.c3.transfer.pojos.RolePlayCharacter</class>
        <class>net.clanwolf.c3.transfer.pojos.RolePlayStoryVar2</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://**.**.**.**:3306/C3?useUnicode=yes&amp;characterEncoding=UTF-8" />
            <property name="current_session_context_class" value="thread" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5Dialect" />

            <!-- Hikari connection pool -->
            <property name="hibernate.hikari.dataSource.url" value="jdbc:mysql://**.**.**.**:3306/C3?useUnicode=yes&amp;characterEncoding=UTF-8" />
            <property name="hibernate.hikari.dataSource.user" value="**"/>
            <property name="hibernate.hikari.maximumPoolSize" value="100" />
            <property name="hibernate.hikari.idleTimeout" value="30000" />
            <property name="hibernate.hikari.dataSource.cachePrepStmts" value="true" />
            <property name="hibernate.hikari.dataSource.prepStmtCacheSize" value="250" />
            <property name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit" value="2048" />
            <property name="hibernate.hikari.dataSource.useServerPrepStmts" value="true" />
        </properties>
    </persistence-unit>
</persistence>

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    ...

    <dependencies>
        <!-- Database persistence -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <!-- <version>5.1.33</version> -->
            <version>6.0.5</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>5.1.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.1.0.Final</version>
            <!-- <version>5.0.3.Final</version> -->
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-ehcache</artifactId>
            <version>5.1.0.Final</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/com.zaxxer/HikariCP -->
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.6.1</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-hikaricp -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-hikaricp</artifactId>
            <version>5.2.7.Final</version>
        </dependency>

        ...

        <!-- Spring -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.2.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.2.2.RELEASE</version>
        </dependency>
        <!--@Transactional -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.2.2.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>4.2.1.RELEASE</version>
        </dependency>

        ...

        <dependency>
            <groupId>org.hibernate.common</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>5.0.0.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.1-api</artifactId>
            <version>1.0.0.Final</version>
        </dependency>

        ...

    </dependencies>
</project>

If I run this in Eclipse, it is all fine:

01:14:05,436 INFO HikariDataSource:70 - HikariPool-1 - Started.

If I run it from the creates jar, it says:

01:11:14,631 WARN ConnectionProviderInitiator:256 - HHH000472: Hikari properties were encountered, but the Hikari ConnectionProvider was not found on the classpath; these properties are going to be ignored. 01:11:14,634 WARN connections:71 - HHH10001002: Using Hibernate built-in connection pool (not for production use!) 01:11:14,639 INFO connections:127 - HHH10001005: using driver [com.mysql.cj.jdbc.Driver] at URL [jdbc:mysql://212.227.253.80:3306/C3?useUnicode=yes&characterEncoding=UTF-8]

The file IS in the classpath for sure and I do not see why it would not be found. Any help is very much appreciated!

Upvotes: 0

Views: 2888

Answers (1)

WarWolfen
WarWolfen

Reputation: 241

Solved.

My project is build with maven-shade. Apparently, if hikariCP is included as class files (not as a jar) in the resulting jar package, it simply does not work. If I provide the CP jars in file system next to my jar and add them to the manifest, they are found.

I have no idea why it would not just use the class files in the package in the first place, but well... They are in that files and they are in the right position, but hikari won't see them.

Upvotes: 0

Related Questions