3

I'm trying to integrate Apache POI in Liferay DXP(OSGi), but unable to resolve dependencies with POI 3.17 version in gradle project. I've created standalone project with below JAR's :

  1. poi-3.17.jar
  2. poi-ooxml-3.17.jar
  3. poi-ooxml-schemas-3.17.jar
  4. xmlbeans-2.6.0.jar
  5. commons-collections4-4.1.jar

Also, I've added below gradle dependencies added in build.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'

Moreover, respective jars also provided into bnd.bnd as well. Any clue what I'm missing here?

Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25

3 Answers3

5

After a lot investigation, I found the solution and correct dependencies management for Liferay DXP and Apache POI integration.

Add below dependencies in 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'

Add below Properties in bnd.bnd file

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*,\ *

once you added these properties in given files. module will deploy successfully and easily integrate ApachePOI into Liferay DXP.

Ashish Dadhich
  • 4,737
  • 4
  • 17
  • 25
0

Below is osgi bundle file(bnd.bnd) for apache-poi-4.0.0 and Liferay 7. Unfortunately, your portlet jar file will be at least 27MB. You must deploy some common libraries by using 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
burhan
  • 11
  • 1
  • 3
0

From Liferay DXP 7.4u55 / CE 7.4ga55 we have shared dependencies modules for POI. So we can add in our build.gradle:

compileOnly group: 'com.liferay', name: 'com.liferay.shared.dependencies.poi'

In this way we can use the Liferay exported packages instead include it in our bundled jar.

After we have imported this dependency we can find it under "External Libraries" (if you use IntelliJ IDE).

This is the link to the shared module of Liferay CE GitHub repository: https://github.com/liferay/liferay-portal/tree/7.4.3.55-ga55/modules/apps/shared-dependencies/shared-dependencies-poi