如何将Liferay DXP与Apache POI集成?

时间:2017-10-29 19:38:08

标签: excel apache-poi build.gradle liferay-7 liferay-dxp

我正在尝试将Apache POI集成到 Liferay DXP(OSGi)中,但无法解决gradle项目中POI 3.17版本的依赖关系。 我用JAR下面创建了独立项目:

  1. POI-3.17.jar
  2. POI-OOXML-3.17.jar
  3. POI-OOXML-架构 - 3.17.jar
  4. 的xmlbeans-2.6.0.jar
  5. 公地collections4-4.1.jar
  6. 另外,我添加了 build.gradle

    中添加的以下gradle依赖项
    compile group: 'org.apache.poi', name: 'poi', version: '3.17'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
    compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
    compile group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '2.6.0'
    compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
    

    此外,各个罐子也提供给 bnd.bnd 。 有什么线索我在这里缺少什么?

2 个答案:

答案 0 :(得分:3)

经过大量调查后,我找到了Liferay DXP和Apache POI集成的解决方案和正确的依赖关系管理。

在build.gradle中添加以下依赖项:

  • compile group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
  • compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
  • compile group: 'org.apache.poi', name: 'poi', version: '3.17'
  • compile group: 'org.apache.poi', name: 'poi-excelant', version: '3.17'
  • compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
  • compile group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
  • compile group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
  • compile group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'
  • compile group: 'org.apache.poi', name: 'ooxml-security', version: '1.1'
  • compile group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '2.6.0'

在bnd.bnd文件中添加以下属性

Include-Resource:\ @commons-collections4-4.1.jar,\ @commons-lang3-3.4.jar,\ @ooxml-schemas-1.3.jar,\ @ooxml-security-1.1.jar,\ @poi-3.17.jar,\ @poi-ooxml-3.17.jar,\ @poi-ooxml-schemas-3.17.jar,\ @poi-excelant-3.17.jar,\ @poi-scratchpad-3.17.jar,\ @xmlbeans-2.6.0.jar

Import-Package: \ !com.sun.*,\ !junit*,\ !org.apache.avalon.framework.logger,\ !org.apache.crimson.jaxp,\ !org.apache.jcp.xml.dsig.internal.dom,\ !org.apache.log,\ !org.apache.xml.resolver*,\ !org.bouncycastle.*,\ !org.gjt.xpp,\ !org.junit*,\ !org.relaxng.datatype,\ !org.xmlpull.v1,\ !com.graphbuilder*,\ *

在给定文件中添加这些属性后。模块将成功部署并轻松将ApachePOI集成到Liferay DXP中。

答案 1 :(得分:0)

以下是apgi-poi-4.0.0和Liferay 7的osgi捆绑文件(bnd.bnd)。 不幸的是,您的portlet jar文件将至少为27MB。您必须使用Blade Client部署一些常见的库

java -jar blade.jar sh start http://repo1.maven.org/maven2/org/apache/commons/commons-collections4/4.2/commons-collections4-4.2.jar
java -jar blade.jar sh start http://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.18/commons-compress-1.18.jar
java -jar blade.jar sh start http://repo1.maven.org/maven2/org/apache/commons/commons-lang3/3.8/commons-lang3-3.8.jar
java -jar blade.jar sh start http://repo1.maven.org/maven2/commons-codec/commons-codec/1.11/commons-codec-1.11.jar
java -jar blade.jar sh start http://repo1.maven.org/maven2/org/apache/commons/commons-math3/3.6.1/commons-math3-3.6.1.jar

Bundle File:    

Bundle-Name: [your-bundle-name]
Bundle-SymbolicName: [your-bundle-symbolicname]
Bundle-Version: 1.0
-jsp: *.jsp,*.jspf
-plugin.jsp: com.liferay.ant.bnd.jsp.JspAnalyzerPlugin
-plugin.resourcebundle: 
com.liferay.ant.bnd.resource.bundle.ResourceBundleLoaderAnalyzerPlugin
-plugin.sass: com.liferay.ant.bnd.sass.SassAnalyzerPlugin
-sass: *

Import-Package:\
    !com.sun.*, \
    !com.graphbuilder*, \
    !org.apache.jcp.xml.dsig.internal.dom, \
    !org.bouncycastle.*, \
    *

Include-Resource:\
    @poi-4.0.0.jar, \
    @poi-excelant-4.0.0.jar, \
    @poi-ooxml-4.0.0.jar, \
    @poi-ooxml-schemas-4.0.0.jar, \
    @poi-scratchpad-4.0.0.jar, \
    @ooxml-schemas-1.4.jar, \
    @ooxml-security-1.1.jar, \
    @xmlbeans-3.0.1.jar