HikariCP

时间:2017-06-08 00:03:04

标签: java maven hikaricp

尝试使用我的应用程序编译HikariCP时,我收到java.lang.NoClassDefFoundError: com/zaxxer/hikari/HikariConfig错误。

它构建到.jar文件中,但似乎在运行时应用程序找不到它。

<?xml version="1.0" encoding="UTF-8"?>
<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>me.MyApp.App</groupId>
    <artifactId>App</artifactId>
    <version>1.0-SNAPSHOT</version>



    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.0.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>me.MyApp.App</mainClass>
                        </manifest>
                        <manifestEntries>
                            <Class-Path>.</Class-Path>
                        </manifestEntries>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


    <dependencies>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>2.6.2</version>
            <scope>compile</scope>
        </dependency>
    </dependencies>



</project>

我认为添加Assembly插件会修复它,但事实并非如此。我做错了什么?

1 个答案:

答案 0 :(得分:0)

因为你有这个:

                <archive>
                    <manifest>
                        <mainClass>me.MyApp.App</mainClass>
                    </manifest>
                    <manifestEntries>
                        <Class-Path>.</Class-Path>
                    </manifestEntries>
                </archive>

...我认为这意味着MANIFEST.MF中的Class-Path条目只是一个“。” (即仅当前目录 - 没有JAR文件)。

我建议您将其更改为:

                <archive>
                    <manifest>
                        <mainClass>me.MyApp.App</mainClass>
                        <addClasspath>true</addClasspath>
                    </manifest>
                </archive>

Reference Link