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

时间:2015-03-11 10:00:53

标签: java jpa osgi websphere-liberty

我有一个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 个答案:

答案 0 :(得分:0)

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