websphere liberty - SLF4J jars 与 websphere 内部包冲突

Posted

技术标签:

【中文标题】websphere liberty - SLF4J jars 与 websphere 内部包冲突【英文标题】:websphere liberty - SLF4J jars conflicting with websphere internal bundles 【发布时间】:2015-05-13 01:23:06 【问题描述】:

我有一个 OSGi 应用程序,它包含 3 个捆绑包 -

1 - LoggingWrapper,充当 log4j 和 slf4j jar 的包装器,并导出 org.slf4j.* 包。

2 - MyProject,其中包含 JPA 代码,并导入以下包:

Import-Package: javax.management,
 javax.naming,
 javax.persistence;version="1.1.0",
 javax.persistence.criteria;version="1.1.0",
 javax.persistence.metamodel;version="1.1.0",
 javax.sql;version="0.0.0",
 javax.transaction;version="1.1.0",
 javax.transaction.xa;version="1.1.0",
 org.apache.openjpa.enhance;version="2.2.0",
 org.apache.openjpa.util;version="2.2.0",
 org.slf4j

在服务器上部署它会导致以下错误:

[AUDIT   ] CWWKZ0404E: An exception was generated when trying to resolve the contents of the application JpaTestApp.  The exception text from the OSGi framework is: Uses constraint violation. Unable to resolve resource MyProject [IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/defaultServer/apps/JpaTestApp.eba/MyProject_1.0.0.jar] because it is exposed to package 'org.slf4j' from resources LoggingWrapper [IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/defaultServer/apps/JpaTestApp.eba/LoggingWrapper_1.0.0.jar] and com.ibm.ws.slf4j-api.1.7.7 [osgi.identity; osgi.identity="com.ibm.ws.slf4j-api.1.7.7"; type="osgi.bundle"; version:Version="1.0.7.cl50420141211-1039"] via two dependency chains.

Chain 1:
  MyProject [IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/defaultServer/apps/JpaTestApp.eba/MyProject_1.0.0.jar]
    import: (&(osgi.wiring.package=org.slf4j)(version>=0.0.0))
     |
    export: osgi.wiring.package: org.slf4j
  LoggingWrapper [IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/defaultServer/apps/JpaTestApp.eba/LoggingWrapper_1.0.0.jar]

Chain 2:
  MyProject [IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/defaultServer/apps/JpaTestApp.eba/MyProject_1.0.0.jar]
    import: (&(osgi.wiring.package=org.apache.openjpa.util)(version>=2.2.0))
     |
    export: osgi.wiring.package=org.apache.openjpa.util; uses:=org.slf4j
  com.ibm.ws.jpa [osgi.identity; osgi.identity="com.ibm.ws.jpa"; type="osgi.bundle"; version:Version="1.0.7.cl50420141211-1039"]
    import: (osgi.wiring.package=org.slf4j)
     |
    export: osgi.wiring.package: org.slf4j
  com.ibm.ws.slf4j-api.1.7.7 [osgi.identity; osgi.identity="com.ibm.ws.slf4j-api.1.7.7"; type="osgi.bundle"; version:Version="1.0.7.cl50420141211-1039"]
[AUDIT   ] CWWKZ0020I: Application JpaTestApp not updated.

从应用程序中删除“LoggingWrapper”包会导致以下错误:

[AUDIT   ] CWWKZ0058I: Monitoring dropins for applications. 
[AUDIT   ] CWWKZ0404E: An exception was generated when trying to resolve the contents of the application JpaTestApp.  The exception text from the OSGi framework is: Unable to resolve IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/experimentalServer/apps/JpaTestApp.eba/XLetDBUtility_1.0.0.jar: missing requirement org.apache.aries.subsystem.core.archive.ImportPackageRequirement: namespace=osgi.wiring.package, attributes=, directives=filter=(&(osgi.wiring.package=org.slf4j)(version>=0.0.0)), resource=IFileAdapter wrapping file with url file:/D:/programs/WebSphere/liberty/wlp/usr/servers/experimentalServer/apps/JpaTestApp.eba/XLetDBUtility_1.0.0.jar
[AUDIT   ] CWWKZ0012I: The application JpaTestApp was not started.

如何解决这些错误?

【问题讨论】:

【参考方案1】:

虽然 Liberty 旨在将应用程序与运行时中包含的开源库(例如 slf4j)隔离开来,但如果导入一些 openjpa 包,似乎会有一点泄漏。您应该能够在您的应用程序中使用 JPA,而无需导入 org.apache.openjpa* 包,因此最好的办法是避免使用它们。切换到动态运行时增强(而不是构建时增强)将节省构建步骤并允许您删除 openjpa 包导入。

【讨论】:

不包括 org.apache.openjpa.* 依赖项给了我错误org.apache.openjpa.enhance.PersistenceCapable was not found by MyProject_1.0.0。我目前也没有使用构建时间增强,尽管我已经尝试这样做来解决这个问题。如何启用动态增强(假设它不是默认设置)? 我检查了我是否使用反编译器使用构建时增强 - 增强的类继承自 PersistenceCapable。部署的类文件没有增强。此外,删除 org.slf4j 但保留 openjpa 依赖项允许我使用捆绑包,但阻止我在其中使用记录器。

以上是关于websphere liberty - SLF4J jars 与 websphere 内部包冲突的主要内容,如果未能解决你的问题,请参考以下文章

将 LDAP 配置从 Websphere 迁移到 Liberty

Liberty Websphere 上没有共同的密码套件

将修订包应用到 WebSphere Liberty Profile

WebSphere Liberty Web 套接字丢失消息

OpenLiberty - IBM首次公开WebSphere Liberty开源版本!

Websphere Liberty Profile 上 Worklight 服务器的拓扑