OSGi中的Apache Jena与Glassfish - ClassCastException

时间:2013-08-15 08:26:47

标签: java glassfish osgi jena

我正在尝试创建一个使用Apache Jena的基于OSGi的应用程序。我创建了一个Jena包,它内联jena-core及其依赖项,并导出相关的包(com.hp.hpl.jena。*)。项目的整体结构如下:

  • 包含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>

我对OSGI的理解是,只有我导出的软件包才能在软件包外部看到,内部软件包可以安全地避免这种奇怪的交互。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

Apache Jena现在包含一个OSGi包jena-osgi