【问题标题】:NoClassDefFoundError with HikariCPHikariCP 的 NoClassDefFoundError
【发布时间】:2017-11-09 12:16:26
【问题描述】:

尝试使用我的应用程序编译 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 插件可以解决问题,但事实并非如此。我做错了什么?

【问题讨论】:

  • 编辑:从 Intellij 中“提取”输出似乎可行,但为什么呢?为什么没有 Maven 专用设置?

标签: java maven hikaricp


【解决方案1】:

因为你有这个:

                <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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-11-29
    • 2016-06-20
    • 1970-01-01
    • 2018-01-03
    • 2019-10-13
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    相关资源
    最近更新 更多