问题
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 :
- poi-3.17.jar
- poi-ooxml-3.17.jar
- poi-ooxml-schemas-3.17.jar
- xmlbeans-2.6.0.jar
- 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?
回答1:
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.
回答2:
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
来源:https://stackoverflow.com/questions/47004439/how-to-integrate-liferay-dxp-with-apache-poi