简体   繁体   English

java.lang.NoClassDefFoundError: OSGi 中的 org/slf4j/LoggerFactory

[英]java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in OSGi

I'm trying to get the library BioJava to work inside an OSGi context.我试图让库BioJava在 OSGi 上下文中工作。

To get the JAR into the OSGi context, I'm using the Maven plugin p2-maven-plugin , which generates a file Manifest.MF , and the part relevant to the exception I'm facing is:为了让 JAR 进入 OSGi 上下文,我使用了 Maven 插件p2-maven-plugin ,它生成一个文件Manifest.MF ,与我面临的异常相关的部分是:

Bundle-SymbolicName: org.biojava.core
Bundle-Version: 5.3.0
Import-Package: [snip],
 org.slf4j;resolution:=optional,
 [snap]

Which looks okay to me.对我来说这看起来没问题。 However when I access a class that uses slf4j I get the titular exception:但是,当我访问一个使用 slf4j 的类时,我得到了名义上的异常:

java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
    at org.biojava.nbio.core.sequence.template.AbstractCompoundSet.<clinit>(AbstractCompoundSet.java:40)
    at org.biojava.nbio.core.sequence.io.ABITrace.getSequence(ABITrace.java:179)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory cannot be found by org.biojava.core_5.3.0
    at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:511)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:422)
    at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:414)

Now it's easy to find this exception everywhere, because a lot of people have tried (and failed) to install slf4j.现在很容易在任何地方找到这个异常,因为很多人都尝试过(但失败了)安装 slf4j。 I checked sites like the documentation or the SO question ClassNotFoundException: org.slf4j.LoggerFactory and hence tried to add the following bundles:我检查了诸如文档或 SO 问题ClassNotFoundException: org.slf4j.LoggerFactory 之类的站点,因此尝试添加以下包:

  • slf4j-simple slf4j-简单
  • slf4j-log4j12 (plus the log4j dependencies) slf4j-log4j12(加上 log4j 依赖项)
  • pax-logging-log4j2 pax-logging-log4j2

However neither worked.然而,两者都没有奏效。 Maybe the OSGi container is having problems, but slf4j JARs have the bundle information with the export packages out of the box, so I'm assuming these work.也许 OSGi 容器有问题,但是 slf4j JAR 具有开箱即用的导出包的捆绑信息,所以我假设这些工作正常。 And the BioJava JAR has an import package, so I have no idea why it wouldn't be able to find the class.而且 BioJava JAR 有一个导入包,所以我不知道为什么它无法找到该类。

Oh, I checked, the LoggerFactory is present in slf4j-api, so it's not that, either.哦,我检查过, LoggerFactory存在于 slf4j-api 中,所以也不是那样。

I also tried different start levels and autostart for the implementations.我还为实现尝试了不同的启动级别和自动启动。 And I rebundled the JAR without the optional dependency, but I keep having problems because now the MD5 hash is broken.我在没有可选依赖项的情况下重新捆绑了 JAR,但我一直遇到问题,因为现在 MD5 散列被破坏了。

Has anybody managed to get slf4j to work in OSGi?有没有人设法让 slf4j 在 OSGi 中工作? Or failing that, is there any way to replace that stupid dependency with some kind of Java proxy so I will not need the broken dependency anymore?或者失败了,有没有办法用某种 Java 代理替换那个愚蠢的依赖项,这样我就不再需要损坏的依赖项了?

resolution:=optional means that when the bundle resolves, it will either get access to the package or not. resolution:=optional意味着当包解析时,它要么可以访问包,要么不能。 The framework is permitted to resolve the bundle without access to the package.允许框架在不访问包的情况下解析包。 If the bundle needs access to the package, why make resolution of the package optional?如果捆绑包需要访问包,为什么要将包的解析设为可选?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 休眠-java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Hibernate - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 问题 - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory problem Slf4j 和 Logback 错误:java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory - Slf4j and Logback error: java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Java:线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Java: Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory Spring工具套件中的线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory in Spring tool suite Gradle-线程“ main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - Gradle - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory XUGGLE ERROR:线程“main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - XUGGLE ERROR: Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory 如何解决java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory? - How can I resolve java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory? java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory即使我有正确的依赖关系 - java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory even though I have the right dependencies RabbitMQ - 线程“main”中的异常java.lang.NoClassDefFoundError:org / slf4j / LoggerFactory - RabbitMQ - Exception in thread “main” java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM