maven 依赖 + 构建路径中的本地 jar = slf4j 冲突
maven dependency + local jar in build path = slf4j conflict
我尝试使用 IMPINJ Octane SDK Java,它作为一个 jar 提供,包括所有需要的依赖项以及 maven 项目中的 Spark 框架。为了包含我使用 maven 的 Spark 框架,并且将 Octane SDK jar 添加到构建路径。我的 pom.xml 只有 spark 依赖项:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
每次我尝试 运行 该程序时,我都会遇到以下错误。
Exception in thread "Thread-1" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:619)
at org.eclipse.jetty.util.log.JettyAwareLogger.info(JettyAwareLogger.java:314)
at org.eclipse.jetty.util.log.Slf4jLog.info(Slf4jLog.java:74)
at org.eclipse.jetty.util.log.Log.initialized(Log.java:186)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:298)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:288)
at org.eclipse.jetty.util.component.AbstractLifeCycle.<clinit>(AbstractLifeCycle.java:35)
at spark.embeddedserver.jetty.EmbeddedJettyFactory.create(EmbeddedJettyFactory.java:34)
at spark.embeddedserver.EmbeddedServers.create(EmbeddedServers.java:57)
at spark.Service.lambda$init[=11=](Service.java:342)
at java.lang.Thread.run(Thread.java:745)
Octane SDK 自带 slf4j,Spark Framework 也有 slf4j 作为依赖,但它们有不同的版本。我找到了以下线程 NoSuchMethodError with SLF4J API,但由于我可以从 jar 中删除 slf4j,所以我无法解决问题。我怎样才能让它工作?
我也尝试在 pom 中排除 slf4j,但它也不起作用:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
编辑(解决方案):
我提取了 Octane SDK jar,删除了 slf4j 并将其压缩回 jar。
我的理解是sparks需要slf4j 1.7.13。
然后,将 Octane 添加到类路径(不是通过 Maven 依赖项),并且此 Octane jar 包含较旧的 类 of slf4j.
我刚刚下载了 Octane 来亲眼看看。我注意到它包括 2 个版本:
- OctaneSDKJava-1.22.0.30.jar
- OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar
您需要使用 OctaneSDKJava-1.22.0.30.jar 并手动包含所有其他依赖项但不是 slf4j 依赖项(或者相反,使用 OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar 并删除 slf4j).
编辑以回答评论中的问题:
我打开了最新的 OctaneSDKJava-1.26.2.0-jar-with-dependencies.zip,其中包含一个 README.txt,详细信息如下:
DEPENDENCIES
RUNTIME DEPENDENCIES
- jdom 1.0 http://www.jdom.org
- log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
- jargs 1.0 http://sourceforge.net/project/showfiles.php?group_id=33024
- mina 1.1.7 http://mina.apache.org
- slf4j-log4j12 1.5.0 http://www.slf4j.org
- slf4j-api 1.5.0 http://www.slf4j.org
- xerces-j 2.4.0 http://xerces.apache.org/
COMPILE DEPENDENCIES
- velocity-dep 1.5 http://velocity.apache.org
- jalopy 0.3.1 http://jalopy.sourceforge.net
- jdom 1.0 http://www.jdom.org
- log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
- commons-collection 3.2 http://commons.apache.org
- commons-configuration 1.5 http://commons.apache.org
- commons-lang 2.3 http://commons.apache.org
- common-logging 1.1.1 http://commons.apache.org
JAXB RI dependencies including:
- jaxb-xjc 2.0 https://jaxb.dev.java.net/
- jaxb-impl 2.0 https://jaxb.dev.java.net/
- jaxb-api 2.0 https://jaxb.dev.java.net/
- activation 2.0 https://jaxb.dev.java.net/
- jsr173_1.0_api 2.0 https://jaxb.dev.java.net/
The five above jaxb dependencies are available in a single jar "JAXB
RI" from https://jaxb.dev.java.net/. Execute this jar (doubleclick
windows, "java -jar " all other platforms) and copy the
individual jars to the LTKJava/lib directory) plus above runtime
dependencies
TEST DEPENDENCIES
- JUnit 4.4 http://sourceforge.net/project/showfiles.php?group_id=15278
plus above dependencies note that the junit dependency needs to be
placed in the ANT_HOME/lib directory
我尝试使用 IMPINJ Octane SDK Java,它作为一个 jar 提供,包括所有需要的依赖项以及 maven 项目中的 Spark 框架。为了包含我使用 maven 的 Spark 框架,并且将 Octane SDK jar 添加到构建路径。我的 pom.xml 只有 spark 依赖项:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
每次我尝试 运行 该程序时,我都会遇到以下错误。
Exception in thread "Thread-1" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:619)
at org.eclipse.jetty.util.log.JettyAwareLogger.info(JettyAwareLogger.java:314)
at org.eclipse.jetty.util.log.Slf4jLog.info(Slf4jLog.java:74)
at org.eclipse.jetty.util.log.Log.initialized(Log.java:186)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:298)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:288)
at org.eclipse.jetty.util.component.AbstractLifeCycle.<clinit>(AbstractLifeCycle.java:35)
at spark.embeddedserver.jetty.EmbeddedJettyFactory.create(EmbeddedJettyFactory.java:34)
at spark.embeddedserver.EmbeddedServers.create(EmbeddedServers.java:57)
at spark.Service.lambda$init[=11=](Service.java:342)
at java.lang.Thread.run(Thread.java:745)
Octane SDK 自带 slf4j,Spark Framework 也有 slf4j 作为依赖,但它们有不同的版本。我找到了以下线程 NoSuchMethodError with SLF4J API,但由于我可以从 jar 中删除 slf4j,所以我无法解决问题。我怎样才能让它工作?
我也尝试在 pom 中排除 slf4j,但它也不起作用:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
编辑(解决方案): 我提取了 Octane SDK jar,删除了 slf4j 并将其压缩回 jar。
我的理解是sparks需要slf4j 1.7.13。 然后,将 Octane 添加到类路径(不是通过 Maven 依赖项),并且此 Octane jar 包含较旧的 类 of slf4j.
我刚刚下载了 Octane 来亲眼看看。我注意到它包括 2 个版本:
- OctaneSDKJava-1.22.0.30.jar
- OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar
您需要使用 OctaneSDKJava-1.22.0.30.jar 并手动包含所有其他依赖项但不是 slf4j 依赖项(或者相反,使用 OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar 并删除 slf4j).
编辑以回答评论中的问题:
我打开了最新的 OctaneSDKJava-1.26.2.0-jar-with-dependencies.zip,其中包含一个 README.txt,详细信息如下:
DEPENDENCIES
RUNTIME DEPENDENCIES
- jdom 1.0 http://www.jdom.org
- log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
- jargs 1.0 http://sourceforge.net/project/showfiles.php?group_id=33024
- mina 1.1.7 http://mina.apache.org
- slf4j-log4j12 1.5.0 http://www.slf4j.org
- slf4j-api 1.5.0 http://www.slf4j.org
- xerces-j 2.4.0 http://xerces.apache.org/
COMPILE DEPENDENCIES
- velocity-dep 1.5 http://velocity.apache.org
- jalopy 0.3.1 http://jalopy.sourceforge.net
- jdom 1.0 http://www.jdom.org
- log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
- commons-collection 3.2 http://commons.apache.org
- commons-configuration 1.5 http://commons.apache.org
- commons-lang 2.3 http://commons.apache.org
- common-logging 1.1.1 http://commons.apache.org
JAXB RI dependencies including:
- jaxb-xjc 2.0 https://jaxb.dev.java.net/
- jaxb-impl 2.0 https://jaxb.dev.java.net/
- jaxb-api 2.0 https://jaxb.dev.java.net/
- activation 2.0 https://jaxb.dev.java.net/
- jsr173_1.0_api 2.0 https://jaxb.dev.java.net/
The five above jaxb dependencies are available in a single jar "JAXB RI" from https://jaxb.dev.java.net/. Execute this jar (doubleclick windows, "java -jar " all other platforms) and copy the individual jars to the LTKJava/lib directory) plus above runtime dependencies
TEST DEPENDENCIES
- JUnit 4.4 http://sourceforge.net/project/showfiles.php?group_id=15278 plus above dependencies note that the junit dependency needs to be placed in the ANT_HOME/lib directory