Apache POI包装包的Pax考试问题 [英] Pax Exam issue with Apache POI wrapped bundle

查看:118
本文介绍了Apache POI包装包的Pax考试问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想办法让Apache POI在OSGi捆绑包中工作.这是我没有运气尝试过的历史:

I have been beating my head against the wall trying to get Apache POI to work within an OSGi bundle. Here is the history of what I have tried with no luck:

1)我最初尝试使用预包装的Apache Servicemix POI捆绑包.但是,这有许多我必须部署的依赖项,其中许多是不需要的.即使添加Apache POI servicemix(及其依赖项)后,我还是碰壁了,我仍然遇到缺少类的问题.

1) I initially tried using the pre wrapped Apache Servicemix POI bundle. However this had many dependencies I had to deploy, many of which were not needed. I hit a wall as even after adding Apache POI servicemix (and its dependencies), i was still getting issues with missing classes.

2)由于第一个解决方案中大量不必要的东西,我决定将依赖项包装在bundle中.基本上,我有一个Blueprint服务,可以充当POI功能的包装器.所有单元测试都可以正常工作,但我的pax考试测试失败.

2) Due to the amount of unneeded stuff in the first solution, I decided to wrap up the dependencies inside a bundle. Basically I have a Blueprint service that acts as a wrapper for the POI functionality. All unit tests work fine but my pax exam tests were failing.

起初,它找不到依赖项(通用编解码器,xmlbeans等)的类.因此,我添加了POI和POI OOMXL依赖关系以及它需要的所有其他依赖关系.这解决了大多数类加载器问题.但是,这是我目前所坚持的.该捆绑包开始时很好,但是一旦到达尝试创建excel工作簿的地步,它就会失败,并显示以下堆栈跟踪:

At first, it couldn't find classes that were dependencies (commons-codec,xmlbeans, etc). So I added the POI and POI OOMXL dependencies and all the other dependencies it needed. This solved most of the class loader issues. However this is the one I am currently stuck on. The bundle starts just fine, but once it hits a point where it tries create an excel workbook, it fails with the following stack trace:

java.lang.ClassNotFoundException: com.bea.xml.stream.EventFactory not found by org.ops4j.pax.exam.rbc [104]

at org.apache.felix.framework.BundleWiringImpl.findClassOrResourceByDelegation(BundleWiringImpl.java:1574)
at org.apache.felix.framework.BundleWiringImpl.access$400(BundleWiringImpl.java:79)
at org.apache.felix.framework.BundleWiringImpl$BundleClassLoader.loadClass(BundleWiringImpl.java:2018)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at javax.xml.stream.FactoryFinder.newInstance(FactoryFinder.java:68)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:178)
at javax.xml.stream.FactoryFinder.find(FactoryFinder.java:92)
at javax.xml.stream.XMLEventFactory.newInstance(XMLEventFactory.java:30)

以下是我要包括的依赖项:

Here are the dependencies I am including:

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>${apache.poi.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>${apache.poi.version}</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.9</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.6.0</version>
        </dependency>

似乎pax容器找不到EventFactory.如果有人有任何建议,我将非常感谢您的帮助.

It seems that the pax container cannot find the EventFactory. If anyone has any suggestions i would greatly appreciate the help.

推荐答案

以下是工作POI osgi捆绑包的pom.xml,该捆绑包用于创建XLSX导出.可能由于某些可选的导入功能不支持100%的某些特殊功能,但它适用于标准导出.

Here is pom.xml for a working POI osgi bundle which is used to create XLSX exports. Maybe some exotic feature not 100% percent supported because of optional import, but it works for standard exports.

apache commons bundle是osgi兼容的,因此,如果您使用这些依赖项,则必须起作用(某些commons被其他功能使用,因此并不需要全部).这些功能位于我们的karaf功能文件中,但是您可以在任何OSGi容器中使用来自给定Maven来源的捆绑软件.

The apache commons bundles are osgi compliant, so if you are using with these dependencies it have to work (some of commons is used by other features, so not all is required). The features is in our karaf feature file, but you can use the bundles from the given maven origin in any OSGi container.

<feature name="stax" version="2.4.0">
    <bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.stax-api-1.0/2.4.0</bundle>
    <bundle>mvn:org.apache.servicemix.specs/org.apache.servicemix.specs.jaxb-api-2.2/2.4.0</bundle>
</feature>  

<feature name="repo-apache-commons" version="1.0.0">
    <bundle>mvn:commons-beanutils/commons-beanutils/1.9.2</bundle>
    <bundle>mvn:commons-collections/commons-collections/3.2.1</bundle>
    <bundle>mvn:commons-io/commons-io/2.4</bundle>
    <bundle>mvn:org.apache.commons/commons-pool2/2.4.2</bundle>
    <bundle>mvn:org.apache.commons/commons-dbcp2/2.1.1</bundle>
    <bundle>mvn:commons-codec/commons-codec/1.9</bundle>
</feature>

<feature name="repo-bouncycastle" version="1.46">
    <bundle>mvn:org.bouncycastle/bcprov-jdk16/1.46</bundle>
    <bundle>mvn:org.bouncycastle/bcmail-jdk16/1.46</bundle>
    <bundle>mvn:org.bouncycastle/bctsp-jdk16/1.46</bundle>
</feature> 

POM.XML:

<?xml version="1.0" encoding="ISO-8859-1"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<version>3.13.1</version>

<properties>
    <poi.version>3.13</poi.version>
    <poi.schema.version>1.1</poi.schema.version>
    <poi.security.version>1.0</poi.security.version>
</properties>

<groupId>org.yourgroupid</groupId>
<artifactId>osgi-apache-poi</artifactId>
<packaging>bundle</packaging>
<name>osgi-apache-poi</name>
<description>Apache poi framework</description>

<build>
<plugins>

    <plugin>
    <groupId>org.apache.felix</groupId>
    <artifactId>maven-bundle-plugin</artifactId>
    <extensions>true</extensions>
    <configuration>
        <instructions>
                    <_exportcontents>
                        org.apache.poi.*;version=${poi.version},
                        org.openxmlformats.schemas.*;version=${poi.schema.version},
                        schemasMicrosoftComOfficeExcel.*;version=${poi.schema.version},
                        schemasMicrosoftComOfficeOffice.*;version=${poi.schema.version},
                        schemasMicrosoftComOfficePowerpoint.*;version=${poi.schema.version},
                        schemasMicrosoftComVml.*;version=${poi.schema.version},
                        org.etsi.uri.*;version=${poi.security.version}
                    </_exportcontents>
                    <Import-Package>
                        com.sun.javadoc;resolution:=optional,
                        com.sun.tools.javadoc;resolution:=optional,
                        org.apache.crimson.jaxp;resolution:=optional,
                        org.apache.tools.ant;resolution:=optional,
                        org.apache.tools.ant.taskdefs;resolution:=optional,
                        org.apache.tools.ant.types;resolution:=optional,
                        junit.framework.*;resolution:=optional,
                        junit.textui.*;resolution:=optional,
                        org.junit.*;resolution:=optional,
                        org.apache.xml.security.*;resolution:=optional,
                        org.apache.jcp.xml.dsig.internal.dom.*;resolution:=optional,
                        *
                    </Import-Package>
                    <DynamicImport-Package>
                        org.apache.xmlbeans.*,
                        schemaorg_apache_xmlbeans.*
                    </DynamicImport-Package>

        <!-- bundle supplied resource prefixes -->
        <Include-Resource>{maven-resources}</Include-Resource>

        <!-- Do not inline jars, include as jar files -->
        <!-- There are config files with same name will be overwritten -->
        <Embed-Dependency>*;scope=compile;inline=false</Embed-Dependency>


        </instructions>
    </configuration>
    </plugin>
</plugins>
</build>
<dependencies>
    <!-- Embedded dependencies -->
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>${poi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml-schemas</artifactId>
        <version>${poi.version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>${poi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-scratchpad</artifactId>
        <version>${poi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>ooxml-schemas</artifactId>
        <version>${poi.schema.version}</version>
    </dependency>
    <dependency>
       <groupId>org.apache.poi</groupId>
       <artifactId>ooxml-security</artifactId>
       <version>${poi.security.version}</version>
    </dependency>
</dependencies>

这篇关于Apache POI包装包的Pax考试问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆