excel 如何将Liferay DXP与Apache POI集成?

ykejflvf  于 2023-04-07  发布在  Apache
关注(0)|答案(3)|浏览(90)

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

  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
    另外,我在下面添加了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中也提供了相应的jar。有没有什么线索,我在这里错过了什么?

1cosmwyk

1cosmwyk1#

经过大量调查,我找到了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中。

r55awzrz

r55awzrz2#

下面是apache-poi-4.0.0和Liferay 7的osgi包文件(bnd.bnd)。不幸的是,您的portlet jar文件将至少有27 MB。您必须使用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
enyaitl3

enyaitl33#

在Liferay DXP 7.4u55 / CE 7.4ga55中,我们有POI的共享依赖模块。因此我们可以在我们的build.gradle中添加:

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

通过这种方式,我们可以使用Liferay导出的软件包,而不是将其包含在捆绑的jar中。
在我们导入这个依赖项之后,我们可以在“外部库”下找到它(如果你使用IntelliJ IDE)。
这是Liferay CE GitHub存储库共享模块的链接:https://github.com/liferay/liferay-portal/tree/7.4.3.55-ga55/modules/apps/shared-dependencies/shared-dependencies-poi

相关问题