有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java运行时遇到“此代码不应该进入jar”错误

我创建了一个使用Hikari CP的应用程序,该应用程序的用户遇到以下错误:

java.lang.ExceptionInInitializerError
    at org.slf4j.LoggerFactory.bind(LoggerFactory.java:121) ~[?:?]
    at org.slf4j.LoggerFactory.performInitialization(LoggerFactory.java:111) ~[?:?]
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:268) ~[?:?]
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:241) ~[?:?]
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254) ~[?:?]
    at com.zaxxer.hikari.AbstractHikariConfig.<clinit>(AbstractHikariConfig.java:43) ~[?:?]
Caused by: java.lang.UnsupportedOperationException: This code should have never made it into the jar
    at org.slf4j.impl.StaticLoggerBinder.<init>(StaticLoggerBinder.java:63) ~[?:?]
    at org.slf4j.impl.StaticLoggerBinder.<clinit>(StaticLoggerBinder.java:44) ~[?:?]

我没有包含任何代码,因为我不确定哪些代码与此相关,问题是该应用程序的用户遇到了此错误,我无法在我这方面复制此问题,因为它对我和其他一些人都非常有效,因此我不确定是什么原因导致此特定用户出现此问题。这似乎是在我使用HikariCP创建SQLite连接时发生的

jar是使用Maven创建的,相关依赖项包括:

<dependency>
    <groupId>com.zaxxer</groupId>
    <artifactId>HikariCP</artifactId>
    <version>2.4.1</version>
    <scope>compile</scope>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-api</artifactId>
    <version>1.7.13</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.7.13</version>
</dependency>

共 (1) 个答案

  1. # 1 楼答案

    从SLF4Jwebsite

    Note that SLF4J-enabling your library implies the addition of only a single mandatory dependency, namely slf4j-api.jar. If no binding is found on the class path, then SLF4J will default to a no-operation implementation.

    我假设因为两个类都有相同的名称(StaticLoggerBinder),所以api版本首先被着色

    要解决此问题,请尝试将slf4j-simple依赖项置于slf4j-api依赖项之上