我正在尝试创建一个使用 Apache Jena 的基于 OSGi 的应用程序。我创建了一个内联 jena-core 及其依赖项的 Jena 包,并导出了相关包 (com.hp.hpl.jena.*)。项目的整体结构是这样的:
- 包含耶拿的捆绑包
- 包含内部 API 的捆绑包
- 实现 API 中定义的服务的捆绑包
- 提供这些服务的 WAR 包 RESTful Web 服务
将 Jena 包加载到 Glassfish 中的 autodeploy 文件夹中工作正常,并且日志报告它加载成功。但是,在那里重新启动带有捆绑包的服务器会导致以下异常:
INFO: WEB0169: Created HTTP listener [http-listener-1] on host/port [0.0.0.0:8080]
INFO: WEB0169: Created HTTP listener [http-listener-2] on host/port [0.0.0.0:8181]
INFO: WEB0169: Created HTTP listener [admin-listener] on host/port [0.0.0.0:4848]
INFO: WEB0171: Created virtual server [server]
INFO: WEB0171: Created virtual server [__asadmin]
SEVERE: Digester.getParser:
java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
at javax.xml.parsers.SAXParserFactory.newInstance(SAXParserFactory.java:126)
at org.apache.tomcat.util.digester.Digester.getFactory(Digester.java:526)
at org.apache.tomcat.util.digester.Digester.getParser(Digester.java:730)
at org.apache.catalina.startup.ContextConfig.createContextDigester(ContextConfig.java:647)
at org.apache.catalina.startup.ContextConfig.<clinit>(ContextConfig.java:187)
at com.sun.enterprise.web.EmbeddedWebContainer.createContext(EmbeddedWebContainer.java:217)
at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1832)
...
我的 Jena 包中的 Xerces 解析器似乎与 Glassfish 中的 Xerces 冲突。我的包中的 POM 文件如下所示:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.2.0</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Export-Package>com.hp.hpl.jena.*;org.apache.log4j;org.apache.log4j.*;org.slf4j;org.slf4j.*</Export-Package>
<Embed-Dependency>*;scope=!runtime|provided;type=!pom;inline=true</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<!-- fix the weird imports -->
<Import-Package>!com.ibm.uvm.tools,!com.sun.*,!javax.jmdns,!javax.jms,!javax.jms.*,!javax.microedition.*,!com.google.gson,!org.apache.avalon.framework.*,!org.apache.commons.beanutils,!org.apache.commons.codec.binary,!org.apache.commons.collections,!org.apache.commons.digester,!org.apache.commons.digester.*,!org.apache.commons.jexl2,
!org.apache.commons.jxpath,!org.apache.commons.jxpath.*,
!org.apache.commons.vfs2,!org.apache.commons.vfs2.provider,!org.apache.log,!org.apache.xml.*,!org.apache.commons.jxpath
!org.gjt.xpp,!org.jaxen,!org.jaxen.*,!org.relaxng.datatype,
!org.w3c.dom.ls,!org.xmlpull.v1,!sun.io,!sun.misc,!org.gjt.xpp,*
</Import-Package>
</instructions>
</configuration>
</plugin>
My understanding of OSGI was that only the packages I export are visible outside the bundle, and internal packages are safe from weird interactions like this. Any suggestions?