Forums

angle-left Back

Adding/updating external libs in DXP

Eloy Castro, modified 4 Months ago.

Adding/updating external libs in DXP

Junior Member Posts: 31 Join Date: 10/30/17 Recent Posts
Hi!

I'm developing a portlet in LiferayDXP, using Eclipse. I need to do an excel custom data export. For that, I want to use apache poi libraries.

First, I included apache poi in his 3.9 version, because I needed an .xls file. I used:

compileInclude group: 'org.apache.poi', name: 'poi', version: '3.17'

in my build.gradle file. It worked as expected. Library was downloaded and I could use it.

Now, my problem. Now, I need a .xslx file, so I need the apache poi-ooxml libraries.
I updated my build.gradle file to:
compileInclude group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
    compileInclude group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
    compileInclude group: 'org.apache.poi', name: 'poi', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-excelant', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'
    compileInclude group: 'org.apache.poi', name: 'ooxml-security', version: '1.1'
    compileInclude group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '2.6.0'

But, in my "Project and external Dependencies" I´m still having poi-3.9.jar, and I have no one of the new libraries.

I have done gradle clean, build, buildDependant... but no result.

How can I clean the old library and use all the news?

Too much thanks for your help!
Sushil Patidar, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Expert Posts: 455 Join Date: 10/30/11 Recent Posts
Hi,

But, in my "Project and external Dependencies" I´m still having poi-3.9.jar, and I have no one of the new libraries.

Is there anything else you added in bnd file?

Regards
Eloy Castro, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Junior Member Posts: 31 Join Date: 10/30/17 Recent Posts
Hi,

No, my bnd.bnd file has nothing but the default.

What I have discovered now is really funny:

I had to create a new module project, empty, for Eclipse to refresh al my libraries.

EDIT: Now, Libraries are well, but had to add exceptions in bnd file:
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*,\
    !gnu.gcj,\
    !kaffe.util,\
    !org.apache.env,\
    !org.apache.harmony.luni.util,\
    !sun.rmi.rmic,\
    !sun.tools*,\
    !weblogic,\
    *



By the way, I could deploy my portlet, but when I do
XSSFWorkbook wb = new XSSFWorkbook();

I have this error emoticon
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller
Sushil Patidar, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Expert Posts: 455 Join Date: 10/30/11 Recent Posts
Hi,

I had to create a new module project, empty, for Eclipse to refresh al my libraries.


Did you try to right click on project and refresh or refresh Gradle>Refresh Gradle Project to see your changes. i think it should work.

Regards
Eloy Castro, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Junior Member Posts: 31 Join Date: 10/30/17 Recent Posts
Sushil Patidar:
Hi,

I had to create a new module project, empty, for Eclipse to refresh al my libraries.


Did you try to right click on project and refresh or refresh Gradle>Refresh Gradle Project to see your changes. i think it should work.

Regards


Yes, too many times. But refresh doesn´t work, clean doesn´t work, gradle refresh doesn´t work... emoticon

I think I have done it more than 50 times. Im a bit fed up for today :S

Thanks anyway!
David H Nebinger, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Community Moderator Liferay Legend Posts: 13824 Join Date: 9/1/06 Recent Posts
I get your frustration, Eloy.

When all else fails, you could delete the project files (.classpath and .project and .settings) and re-import into Eclipse. I usually do this as a last resort, but it sounds like you're there too.
Sushil Patidar, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Expert Posts: 455 Join Date: 10/30/11 Recent Posts
Hi Eloy,

Can you check with updating IDE with latest version .
Not sure but might be some help to come out of this pain as on KB . It is mentioned at last para that refresh works in this update.

Regards
Eloy Castro, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Junior Member Posts: 31 Join Date: 10/30/17 Recent Posts
Thanks all for replying. I have my IDE updated to the last version. I have re-imported the module but...I´m still in the same point.

My bnd.bnd file:
* All the exceptions are because when doing "blade deploy", errors like "Unresolved requirement: Import-Package: weblogic" appear continously.

Bundle-Name: myportlet
Bundle-SymbolicName: mypackage
Bundle-Version: 1.0.0
Export-Package: myPackage.constants
Import-Package: \
    !com.sun.javadoc,\
    !com.sun.*,\
    !junit.*,\
    !junit.framework,\
    !org.apache.xmlbeans.*,\
    !org.apache.poi.hsmf,\
    !org.apache.poi.hslf.extractor,\
    !org.apache.poi.hpbf.extractor,\
    !org.apache.poi.*,\
    !org.apache.crimson.jaxp,\
    !org.apache.jcp.xml.dsig.internal.dom,\
    !org.apache.xml.*,\
    !org.bouncycastle.*,\
    !org.junit.*,\
    !org.openxmlformats.schemas.*,\
    !schemasMicrosoftComOfficeExcel,\
    !schemasMicrosoftComOfficeOffice,\
    !schemasMicrosoftComVml,\
    !junit.textui,\
    !gnu.gcj,\
    !kaffe.util,\
    !org.apache.env,\
    !org.apache.harmony.luni.util,\
    !org.gjt.xpp,\
    !org.relaxng.datatype,\
    !org.xmlpull.v1,\
    !sun.rmi.rmic,\
    !sun.tools.javac,\
    !sun.tools.native2ascii,\
    !weblogic,\
    *


My build.gradle:

dependencies {
    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
    compileOnly group: "jstl", name: "jstl", version: "1.2"
    compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
    compileOnly project(":modules:dao:dao-api")
   
    compileInclude group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
    compileInclude group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
    compileInclude group: 'commons-codec', name: 'commons-codec', version: '1.4'
    compileInclude group: 'org.apache.poi', name: 'poi', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-excelant', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
    compileInclude group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'
    compileInclude group: 'org.apache.poi', name: 'ooxml-security', version: '1.1'
    compileInclude group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '2.6.0'
    compileInclude group: 'com.github.virtuald', name: 'curvesapi', version: '1.03'
}


In my portlet´s java file, I can add:
XSSFWorkbook wb = new XSSFWorkbook();


It compiles, but when running the Sentence:
java.lang.NoClassDefFoundError: Could not initialize class org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller

¿How can I use apache poi xml library with liferay DXP?
David H Nebinger, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Community Moderator Liferay Legend Posts: 13824 Join Date: 9/1/06 Recent Posts
The compileInclude directive does not handle all transitive dependencies, likely you are missing openxml4j.

Pull in this one and see if you get farther.
SC
Shin Chan, modified 4 Months ago.

RE: Adding/updating external libs in DXP

New Member Posts: 6 Join Date: 2/15/17 Recent Posts
This is working for me..

build.gradle snippet ..
---
compileOnly group: "org.apache.poi", name: "poi", version: "3.15"
compileOnly group: "org.apache.poi", name: "poi-ooxml", version: "3.15"
compileOnly group: "org.apache.poi", name: "poi-ooxml-schemas", version: "3.15"

compileOnly group: "commons-codec", name: "commons-codec", version: "1.10"
compileOnly group: "org.apache.commons", name: "commons-collections4", version: "4.1"
compileOnly group: "com.github.virtuald", name: "curvesapi", version: "1.04"
compileOnly group: "org.apache.xmlbeans", name: "xmlbeans", version: "2.6.0"
---

bnd.bnd snippet ..
---
Import-Package: \
com.microsoft.schemas.office.*; resolution:=optional,\
junit.framework.*; resolution:=optional,\
org.junit.*; resolution:=optional,\
org.apache.jcp.xml.dsig.internal.dom.*; resolution:=optional,\
com.sun.javadoc.*; resolution:=optional,\
com.sun.tools.*; resolution:=optional,\
org.apache.crimson.*; resolution:=optional,\
org.apache.poi.hslf.*; resolution:=optional,\
org.apache.poi.hsmf.*; resolution:=optional,\
org.apache.poi.hwpf.*; resolution:=optional,\
org.apache.xml.resolver.*; resolution:=optional,\
org.bouncycastle.asn1.*; resolution:=optional,\
org.bouncycastle.cert.*; resolution:=optional,\
org.bouncycastle.cms.*; resolution:=optional,\
org.bouncycastle.operator.*; resolution:=optional,\
org.bouncycastle.tsp.*; resolution:=optional,\
org.bouncycastle.util.*; resolution:=optional,\
javax.xml.crypto.*; resolution:=optional,\
org.apache.xml.security.*; resolution:=optional,\
org.openxmlformats.schemas.*; resolution:=optional,\
*

Include-Resource: \
@poi-3.15.jar,\
@poi-ooxml-3.15.jar,\
@poi-ooxml-schemas-3.15.jar,\
@commons-codec-1.10.jar,\
@commons-collections4-4.1.jar,\
@curvesapi-1.04.jar,\
@xmlbeans-2.6.0.jar
---
David H Nebinger, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Community Moderator Liferay Legend Posts: 13824 Join Date: 9/1/06 Recent Posts
I really think it is not a good idea to propagate the "optional" resolution into your bundle.

I mean, you should know if some package really is optional or not. The code inside of your bundle may or may not, for example, be taking advantage of encryption using BC. But you know that. And you know if it isn't.

By passing along the "optional" resolution, you give the OSGi container the ability to start your module if BC is not there. But if you need BC to function, OSGi will start your module but it will ultimately fail when BC isn't there.

Trust me, I know it is a pain to track down direct and transitive dependencies. It is a heck of a lot more work than we normally need to do as developers. But I guarantee there is payoff when you are in control of your dependencies rather than abdicating control over to the OSGi container.
David H Nebinger, modified 4 Months ago.

RE: Adding/updating external libs in DXP

Community Moderator Liferay Legend Posts: 13824 Join Date: 9/1/06 Recent Posts
Eloy Castro:
But, in my "Project and external Dependencies" I´m still having poi-3.9.jar, and I have no one of the new libraries.


If you're talking about inside of the IDE, you sometimes have to force it to refresh the project to see the new dependencies.

When you build your jar module, you can always look inside it w/ your favorite zip tool and verify that 3.9 is not in there.