首页 > 解决方案 > Apache POI 约束违规

问题描述

我继承了一个应用程序。这个应用程序使用 poi 3.9 库。它适用于 3.9。我需要创建一个 CSV 到 XML(Excel) 的过程。我需要执行 Workbook.close() - 我发现 3.9 POI 库没有 close 方法,所以我正在尝试升级到更新的版本。我已经尝试了所有这些,它们都产生相同的结果。结果如下:

Error executing command: Could not start bundle wrap:mvn:org.apache.poi/poi-ooxml-schemas/3.16$DynamicImport-package=* in feature(s) my-application-1.0.0: Uses constraint violation. Unable to resolve bundle revision wrap_mvn_org.apache.poi_poi-ooxml-schemas_3.16_DynamicImport-package__ [299.0] because it exports package 'org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes' and is also exposed to it from bundle revision org.apache.servicemix.bundles.poi [300.0] via the following dependency chain:

  wrap_mvn_org.apache.poi_poi-ooxml-schemas_3.16_DynamicImport-package__ [299.0]
    import: (osgi.wiring.package=org.apache.poi)
     |
    export: osgi.wiring.package=org.apache.poi; uses:=org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes
    export: osgi.wiring.package=org.openxmlformats.schemas.officeDocument.x2006.docPropsVTypes
  org.apache.servicemix.bundles.poi [300.0]

3.9 不会标记此错误。有了这个配置。特点 XML

<?xml version="1.0" encoding="UTF-8"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
<feature name="my-application" version="1.0.0" description="myapp Route and dependencies">
<feature>camel-core</feature>
<feature>camel-blueprint</feature>
<feature>camel-csv</feature>
<feature>camel-sql</feature>
<feature>camel-jdbc</feature>
<feature>camel-velocity</feature>
<feature>camel-xmlbeans</feature>

        <bundle start-level="60">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
<bundle start-level="61">wrap:mvn:org.apache.poi/poi-ooxml-schemas/3.16$DynamicImport-package=*</bundle>
<bundle start-level="65">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi/3.16_1</bundle>

        <bundle>mvn:com.ibm.msg.client.osgi/osgi-jms/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq-prereq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-nls/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq-nls/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-commonservices-j2se/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/jms-prereq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.mq.osgi/osgi-directip/7.5.0.2</bundle>

        <bundle start-level="80">wrap:mvn:com.enterprisemath/em-utils/2.4.0</bundle>
        <bundle start-level="80">wrap:mvn:org.apache.commons/commons-collections4/4.1</bundle>
        <bundle start-level="80">wrap:mvn:mysql/mysql-connector-java/5.1.45</bundle>
        <bundle start-level="84">wrap:mvn:com.mchange/mchange-commons-java/0.2.11</bundle>
        <bundle start-level="85">wrap:mvn:com.mchange/c3p0/0.9.5.2$Bundle-SymbolicName=c3p0-0.9.5.2&amp;Import-package=*;resolution:=optional;version=0</bundle>
        <bundle start-level="85">wrap:mvn:org.springframework/spring-jdbc/4.0.4.RELEASE$Import-package=com.mysql.jdbc;resolution:=optional;version=0,javax.sql;resolution:=optional;version=0,org.apache.commons.logging;resolution:=optional;version=0,org.springframework.util;resolution:=0;version=0</bundle>

        <bundle start-level="90">mvn:com.ge.ip.infra/myapp-prod/3.0.1-SNAPSHOT</bundle>
    </feature>
</features>

聚甲醛

<dependency>
  <groupId>org.apache.servicemix.bundles</groupId>
  <artifactId>org.apache.servicemix.bundles.poi</artifactId>
  <version>3.16_1</version>  <!-- 3.9_2, 3.14_1 -->
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>3.16</version>  <!-- 3.9, 3.14-->
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>3.16</version> <!-- 3.9, 3.14 -->
</dependency>

如果 servicemix 包 Apache ServiceMix :: Bundles :: POI 这个 OSGi 包包含 poi、poi-contrib、poi-ooxml、poi-ooxml-schemas 和 poi-scratchpad 4.0.0 jar 文件。
我需要在 features xml 中导入 poi 吗?如果 servicemix 包包含它?

3.9 版以上 POI 的正确 POM/功能 xml 安排是什么?

POI 依赖项可能有点吓人。谢谢你!!!

2018-12-18

我尝试了 3.17_1/3.17 和 4.0.0_1/4.0.1 但现在出现编译时错误,看起来现在我缺少了一些东西,找不到 XSSF 组件

[错误] 符号:变量 CELL_TYPE_FORMULA 位置:类 XSSFCell C:\Users\212555427\devel\workspaces\jbds\iprcsmartsignal\myapp-New\src\main\java\com\ge\ip\infra\fadec\asset\AssetXlsxProcessor。 java:[236,56] 错误:不兼容的类型:CellType 无法转换为 int [错误] C:\Users\212555427\devel\workspaces\jbds\iprcsmartsignal\myapp-New\src\main\java\com\ge\ ip\infra\fadec\asset\AssetXlsxProcessor.java:[239,29] 错误:找不到符号 [ERROR] 符号:变量 CELL_TYPE_STRING 位置:类 XSSFCell C:\Users\212555427\devel\workspaces\jbds\iprcsmartsignal\myapp- New\src\main\java\com\ge\ip\infra\fadec\asset\AssetXlsxProcessor.java:[242,29] 错误:找不到符号 [ERROR] 符号:变量 CELL_TYPE_NUMERIC 位置:XSSFCell 类


我已经尝试为 4.0.1 导入所有 poi 依赖项,但现在我失去了对任何 XSSF 的引用,茫然和困惑,非常感谢专家的建议。感谢 POM POI 条目

<!-- Java Apache POI Excel dependencies -->      
<dependency>
  <groupId>org.apache.servicemix.bundles</groupId>
  <artifactId>org.apache.servicemix.bundles.poi</artifactId>
  <version>4.0.0_1</version>  <!-- 3.9_2, 3.14_1 -->
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml</artifactId>
    <version>4.0.1</version>  <!-- 3.9, 3.14-->
</dependency>
<dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>poi-ooxml-schemas</artifactId>
    <version>4.0.1</version> <!-- 3.9, 3.14 -->
</dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-collections4</artifactId>
    <version>4.2</version>
</dependency>
  <dependency>
    <groupId>org.apache.poi</groupId>
    <artifactId>ooxml-schemas</artifactId>
    <version>1.4</version>
  </dependency>
<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-math3</artifactId>
    <version>3.6.1</version>
</dependency>
<dependency>
  <groupId>commons-codec</groupId>
  <artifactId>commons-codec</artifactId>
  <version>1.11</version>
</dependency>
<dependency>
  <groupId>org.apache.commons</groupId>
  <artifactId>commons-compress</artifactId>
  <version>1.18</version>
</dependency>

类进口

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

找不到使用 4.0.1 poi jar 的所有这些 POI 符号。以前的 poi 版本不这样做。我显然对这些新的 poi 库有一些交叉。

private String getCellValueAsString(XSSFWorkbook workbook, XSSFCell cell) {
    String cellValue = "";
    if (cell != null) {
        int cellType = (int)cell.getCellType();
        if (cellType == XSSFCell.CELL_TYPE_FORMULA) {
            FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
            cellType = evaluator.evaluateFormulaCell(cell);
        }
        switch (cellType) {
            case XSSFCell.CELL_TYPE_STRING:
                cellValue = cell.getStringCellValue();
                break;
            case XSSFCell.CELL_TYPE_NUMERIC:
                Double doubleValue = cell.getNumericCellValue();
                int intValue = doubleValue.intValue();
                cellValue = Integer.toString(intValue);
                break;
            case XSSFCell.CELL_TYPE_BOOLEAN:
                cellValue = Boolean.toString(cell.getBooleanCellValue());
                break;
            case XSSFCell.CELL_TYPE_ERROR:
                cellValue = cell.getErrorCellString();
                break;
            case XSSFCell.CELL_TYPE_BLANK:
                break;
            default:
                break;
        }
    }

    return cellValue;
}

好的,我能够使用新的 POI 4.0.1 库克服编译错误。似乎 CellType 枚举值已使用 getCellType 方法更改。

import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

private String getCellValueAsString(XSSFWorkbook workbook, XSSFCell cell) {
    String cellValue = "";
    if (cell != null) {
        CellType cellType = cell.getCellType();
        if (cellType == CellType.FORMULA) {
            FormulaEvaluator evaluator = workbook.getCreationHelper().createFormulaEvaluator();
            cellType = evaluator.evaluateFormulaCell(cell);
        }
        switch (cellType) {
            case STRING:
                cellValue = cell.getStringCellValue();
                break;
            case NUMERIC:
                Double doubleValue = cell.getNumericCellValue();
                int intValue = doubleValue.intValue();
                cellValue = Integer.toString(intValue);
                break;
            case BOOLEAN:
                cellValue = Boolean.toString(cell.getBooleanCellValue());
                break;
            case ERROR:
                cellValue = cell.getErrorCellString();
                break;
            case BLANK:
                break;
            default:
                break;
        }
    }

    return cellValue;
}

现在我需要查看运行时错误是否仍然存在。BRB。谢谢大家

运行时错误现在显示接线问题。

Error executing command: Could not start bundle mvn:com.ge.ip.infra/delta-fadec-prod/3.0.1-SNAPSHOT in feature(s) fadec-application-1.0.0: Unresolved constraint in bundle delta-fadec-prod [339]: Unable to resolve 339.0: missing requirement [339.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.poi.ss.usermodel)(version>=3.16.0)(!(version>=4.0.0)))

显现

Manifest-Version: 1.0
Bnd-LastModified: 1545169168881
Build-Jdk: 1.8.0_181
Bundle-ManifestVersion: 2
Bundle-Name: FADEC PROD ENV
Bundle-SymbolicName: fadec-prod
Bundle-Version: 3.0.1.SNAPSHOT
Created-By: Apache Maven Bundle Plugin
Export-Package: com.ge.ip.infra.fadec;uses:="org.apache.camel,org.slf4j,
 org.apache.camel.processor.aggregate,org.joda.time,com.ge.ip.infra.fade
 c.domain,org.joda.time.format,com.ge.ip.infra.fadec.exception,javax.sql
 ,com.ge.ip.infra.fadec.asset,com.ge.ip.infra.fadec.decoder,javax.xml.bi
 nd,org.apache.camel.component.file,com.ge.ip.infra.fadec.statusmessage,
 org.apache.camel.component.timer,org.apache.camel.spi";version="3.0.1.S
 NAPSHOT",com.ge.ip.infra.fadec.asset;uses:="org.apache.camel,org.apache
 .camel.processor.aggregate,org.slf4j,org.apache.poi.ss.usermodel,org.ap
 ache.poi.xssf.usermodel,javax.sql";version="3.0.1.SNAPSHOT",com.ge.ip.i
 nfra.fadec.decoder;uses:="javax.xml.bind.annotation";version="3.0.1.SNA
 PSHOT",com.ge.ip.infra.fadec.domain;uses:="com.ge.ip.infra.fadec.decode
 r,org.joda.time";version="3.0.1.SNAPSHOT",com.ge.ip.infra.fadec.excepti
 on;version="3.0.1.SNAPSHOT",com.ge.ip.infra.fadec.management;uses:="org
 .apache.camel.api.management,org.joda.time,org.apache.camel,org.joda.ti
 me.format";version="3.0.1.SNAPSHOT",com.ge.ip.infra.fadec.processors;us
 es:="org.slf4j,com.ge.ip.infra.fadec.processors.entities,org.apache.cam
 el,com.ge.ip.infra.fadec.asset,javax.sql,org.apache.camel.processor.agg
 regate,org.apache.poi.xssf.usermodel,org.apache.log4j,org.apache.common
 s.io";version="3.0.1.SNAPSHOT",com.ge.ip.infra.fadec.processors.entitie
 s;version="3.0.1.SNAPSHOT",com.ge.ip.infra.fadec.processors.regex;uses:
 ="org.slf4j";version="3.0.1.SNAPSHOT",com.ge.ip.infra.fadec.statusmessa
 ge;uses:="org.apache.camel,org.slf4j,org.apache.poi.ss.usermodel,org.ap
 ache.poi.xssf.usermodel";version="3.0.1.SNAPSHOT"
Export-Service: com.ge.ip.infra.fadec.processors.DownloadFileService
Import-Package: com.ge.ip.infra.fadec.processors,com.ge.ip.infra.fadec.p
 rocessors.entities,com.ge.ip.infra.fadec.processors.regex,com.ibm.mq.jm
 s,com.mchange.v2.c3p0,com.mysql.jdbc.jdbc2.optional;version="[5.1,6)",j
 avax.sql,javax.xml.bind,javax.xml.bind.annotation,org.apache.camel;vers
 ion="[2.17,3)",org.apache.camel.api.management;version="[2.17,3)",org.a
 pache.camel.builder;version="[2.17,3)",org.apache.camel.component.file;
 version="[2.17,3)",org.apache.camel.component.jms;version="[2.17,3)",or
 g.apache.camel.component.sql;version="[2.17,3)",org.apache.camel.compon
 ent.timer;version="[2.17,3)",org.apache.camel.processor;version="[2.17,
 3)",org.apache.camel.processor.aggregate;version="[2.17,3)",org.apache.
 camel.spi;version="[2.17,3)",org.apache.commons.io;version="[1.4,2)",or
 g.apache.log4j;version="[1.2,2)",org.apache.poi.ss.usermodel;version="[
 4.0,5)",org.apache.poi.xssf.usermodel;version="[4.0,5)",org.joda.time;v
 ersion="[2.9,3)",org.joda.time.format;version="[2.9,3)",org.osgi.servic
 e.blueprint;version="[1.0.0,2.0.0)",org.slf4j;version="[1.7,2)",org.spr
 ingframework.jdbc,org.springframework.jdbc.core,org.springframework.jms
 .connection
Tool: Bnd-1.50.0

我似乎自己绊倒了这个,请任何帮助将不胜感激。鹅,升级库应该没那么难。我想要的只是能够关闭一个工作簿,3.9 libs 不支持这个,所有其他的都给出了更多的问题。所以,我选择了最新最好的,改变了我能找到的一切来让它发挥作用。谢谢大家!


在路上。。谢谢大家。。

现在我只是遇到 osgi 布线约束问题。最新的是

Unresolved constraint in bundle org.apache.servicemix.bundles.poi [302]: Unable to resolve 302.0: missing requirement [302.0] osgi.wiring.package; (&(osgi.wiring.package=org.apache.commons.compress.archivers)(version>=1.18.0)(!(version>=2.0.0)))

最新功能 xml

<?xml version="1.0" encoding="UTF-8"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
<feature name="myapp-application" version="1.0.0" description="Route and dependencies">
<feature>camel-core</feature>
<feature>camel-blueprint</feature>
<feature>camel-csv</feature>
<feature>camel-sql</feature>
<feature>camel-jdbc</feature>
<feature>camel-velocity</feature>
<feature>camel-xmlbeans</feature>

        <bundle start-level="60">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
        <bundle start-level="61">wrap:mvn:org.apache.poi/poi-ooxml-schemas/4.0.1$DynamicImport-package=*</bundle> 
        <bundle start-level="61">mvn:org.apache.commons/commons-collections4/4.2</bundle>
        <bundle start-level="61">mvn:org.apache.commons/commons-compress/1.8</bundle>
        <bundle start-level="65">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi/4.0.0_1</bundle>

        <bundle>mvn:com.ibm.msg.client.osgi/osgi-jms/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq-prereq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-nls/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq-nls/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-commonservices-j2se/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/jms-prereq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.mq.osgi/osgi-directip/7.5.0.2</bundle>

        <bundle start-level="80">wrap:mvn:com.enterprisemath/em-utils/2.4.0</bundle>
        <bundle start-level="80">wrap:mvn:mysql/mysql-connector-java/5.1.45</bundle>
        <bundle start-level="84">wrap:mvn:com.mchange/mchange-commons-java/0.2.11</bundle>
        <bundle start-level="85">wrap:mvn:com.mchange/c3p0/0.9.5.2$Bundle-SymbolicName=c3p0-0.9.5.2&amp;Import-package=*;resolution:=optional;version=0</bundle>
        <bundle start-level="85">wrap:mvn:org.springframework/spring-jdbc/4.0.4.RELEASE$Import-package=com.mysql.jdbc;resolution:=optional;version=0,javax.sql;resolution:=optional;version=0,org.apache.commons.logging;resolution:=optional;version=0,org.springframework.util;resolution:=0;version=0</bundle>

        <bundle start-level="90">mvn:com.ge.ip.infra/myapp-prod/3.0.1-SNAPSHOT</bundle>
    </feature>
</features>

解决osgi布线依赖问题..到目前为止..

<?xml version="1.0" encoding="UTF-8"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.0.0">
<feature name="myapp-application" version="1.0.0" description="Route and dependencies">
<feature>camel-core</feature>
<feature>camel-blueprint</feature>
<feature>camel-csv</feature>
<feature>camel-sql</feature>
<feature>camel-jdbc</feature>
<feature>camel-velocity</feature>
<feature>camel-xmlbeans</feature>

        <bundle start-level="60">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.dom4j/1.6.1_5</bundle>
        <bundle start-level="61">wrap:mvn:org.apache.poi/poi-ooxml-schemas/4.0.1$DynamicImport-package=*</bundle> <!-- 3.9, 3.14 $DynamicImport-package=*-->
        <bundle start-level="61">wrap:mvn:org.apache.commons/commons-collections4/4.2</bundle>
        <bundle start-level="62">wrap:mvn:org.apache.commons/commons-compress/1.18</bundle>
        <bundle start-level="63">wrap:mvn:org.apache.commons/commons-math3/3.6.1</bundle>
        <bundle start-level="65">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi/4.0.0_1</bundle>  <!-- 3.9_2 3.13_1 3.14-->

        <bundle>mvn:com.ibm.msg.client.osgi/osgi-jms/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq-prereq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-nls/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq-nls/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-wmq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/osgi-commonservices-j2se/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.msg.client.osgi/jms-prereq/7.5.0.2</bundle>
        <bundle>mvn:com.ibm.mq.osgi/osgi-directip/7.5.0.2</bundle>

        <bundle start-level="80">wrap:mvn:com.enterprisemath/em-utils/2.4.0</bundle>
        <bundle start-level="80">wrap:mvn:mysql/mysql-connector-java/5.1.45</bundle>
        <bundle start-level="84">wrap:mvn:com.mchange/mchange-commons-java/0.2.11</bundle>
        <bundle start-level="85">wrap:mvn:com.mchange/c3p0/0.9.5.2$Bundle-SymbolicName=c3p0-0.9.5.2&amp;Import-package=*;resolution:=optional;version=0</bundle>
        <bundle start-level="85">wrap:mvn:org.springframework/spring-jdbc/4.0.4.RELEASE$Import-package=com.mysql.jdbc;resolution:=optional;version=0,javax.sql;resolution:=optional;version=0,org.apache.commons.logging;resolution:=optional;version=0,org.springframework.util;resolution:=0;version=0</bundle>

        <bundle start-level="90">mvn:com.ge.ip.infra/myapp-prod/3.0.1-SNAPSHOT</bundle>
    </feature>
</features>

此配置引发运行时错误 - 有人知道 Maven 存储库或如何将其添加到 POM 和功能中吗?试图找到安全包???谢谢

Error executing command: Could not start bundle mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi/4.0.0_1 in feature(s) fadec-application-1.0.0: Unresolved constraint in bundle org.apache.servicemix.bundles.poi [303]: Unable to resolve 303.0: missing requirement [303.0] osgi.wiring.package; (osgi.wiring.package=org.apache.xml.security.signature)

标签: javaapache-poi

解决方案


推荐阅读