Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Eloy Castro
Adding/updating external libs in DXP
March 27, 2018 11:32 PM
Answer

Eloy Castro

Rank: Junior Member

Posts: 26

Join Date: October 30, 2017

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:

1compileInclude 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:
 1compileInclude group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
 2    compileInclude group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
 3    compileInclude group: 'org.apache.poi', name: 'poi', version: '3.17'
 4    compileInclude group: 'org.apache.poi', name: 'poi-excelant', version: '3.17'
 5    compileInclude group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
 6    compileInclude group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
 7    compileInclude group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
 8    compileInclude group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'
 9    compileInclude group: 'org.apache.poi', name: 'ooxml-security', version: '1.1'
10    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
RE: Adding/updating external libs in DXP
March 28, 2018 3:20 AM
Answer

Sushil Patidar

Rank: Expert

Posts: 448

Join Date: October 30, 2011

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
RE: Adding/updating external libs in DXP
March 28, 2018 3:48 AM
Answer

Eloy Castro

Rank: Junior Member

Posts: 26

Join Date: October 30, 2017

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:
 1Import-Package: \
 2    !com.sun.*,\
 3    !junit*,\
 4    !org.apache.avalon.framework.logger,\
 5    !org.apache.crimson.jaxp,\
 6    !org.apache.jcp.xml.dsig.internal.dom,\
 7    !org.apache.log,\
 8    !org.apache.xml.resolver*,\
 9    !org.bouncycastle.*,\
10    !org.gjt.xpp,\
11    !org.junit*,\
12    !org.relaxng.datatype,\
13    !org.xmlpull.v1,\
14    !com.graphbuilder*,\
15    !gnu.gcj,\
16    !kaffe.util,\
17    !org.apache.env,\
18    !org.apache.harmony.luni.util,\
19    !sun.rmi.rmic,\
20    !sun.tools*,\
21    !weblogic,\
22    *



By the way, I could deploy my portlet, but when I do
1XSSFWorkbook 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
RE: Adding/updating external libs in DXP
March 28, 2018 5:52 AM
Answer

Sushil Patidar

Rank: Expert

Posts: 448

Join Date: October 30, 2011

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
David H Nebinger
RE: Adding/updating external libs in DXP
March 28, 2018 6:32 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 13739

Join Date: September 1, 2006

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.
Eloy Castro
RE: Adding/updating external libs in DXP
March 28, 2018 6:35 AM
Answer

Eloy Castro

Rank: Junior Member

Posts: 26

Join Date: October 30, 2017

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
RE: Adding/updating external libs in DXP
March 28, 2018 6:47 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 13739

Join Date: September 1, 2006

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
RE: Adding/updating external libs in DXP
March 28, 2018 11:27 PM
Answer

Sushil Patidar

Rank: Expert

Posts: 448

Join Date: October 30, 2011

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
RE: Adding/updating external libs in DXP
April 3, 2018 2:56 AM
Answer

Eloy Castro

Rank: Junior Member

Posts: 26

Join Date: October 30, 2017

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.

 1Bundle-Name: myportlet
 2Bundle-SymbolicName: mypackage
 3Bundle-Version: 1.0.0
 4Export-Package: myPackage.constants
 5Import-Package: \
 6    !com.sun.javadoc,\
 7    !com.sun.*,\
 8    !junit.*,\
 9    !junit.framework,\
10    !org.apache.xmlbeans.*,\
11    !org.apache.poi.hsmf,\
12    !org.apache.poi.hslf.extractor,\
13    !org.apache.poi.hpbf.extractor,\
14    !org.apache.poi.*,\
15    !org.apache.crimson.jaxp,\
16    !org.apache.jcp.xml.dsig.internal.dom,\
17    !org.apache.xml.*,\
18    !org.bouncycastle.*,\
19    !org.junit.*,\
20    !org.openxmlformats.schemas.*,\
21    !schemasMicrosoftComOfficeExcel,\
22    !schemasMicrosoftComOfficeOffice,\
23    !schemasMicrosoftComVml,\
24    !junit.textui,\
25    !gnu.gcj,\
26    !kaffe.util,\
27    !org.apache.env,\
28    !org.apache.harmony.luni.util,\
29    !org.gjt.xpp,\
30    !org.relaxng.datatype,\
31    !org.xmlpull.v1,\
32    !sun.rmi.rmic,\
33    !sun.tools.javac,\
34    !sun.tools.native2ascii,\
35    !weblogic,\
36    *


My build.gradle:

 1dependencies {
 2    compileOnly group: "com.liferay.portal", name: "com.liferay.portal.kernel", version: "2.0.0"
 3    compileOnly group: "com.liferay.portal", name: "com.liferay.util.taglib", version: "2.0.0"
 4    compileOnly group: "javax.portlet", name: "portlet-api", version: "2.0"
 5    compileOnly group: "javax.servlet", name: "javax.servlet-api", version: "3.0.1"
 6    compileOnly group: "jstl", name: "jstl", version: "1.2"
 7    compileOnly group: "org.osgi", name: "osgi.cmpn", version: "6.0.0"
 8    compileOnly project(":modules:dao:dao-api")
 9   
10    compileInclude group: 'org.apache.commons', name: 'commons-collections4', version: '4.1'
11    compileInclude group: 'org.apache.commons', name: 'commons-lang3', version: '3.4'
12    compileInclude group: 'commons-codec', name: 'commons-codec', version: '1.4'
13    compileInclude group: 'org.apache.poi', name: 'poi', version: '3.17'
14    compileInclude group: 'org.apache.poi', name: 'poi-excelant', version: '3.17'
15    compileInclude group: 'org.apache.poi', name: 'poi-ooxml', version: '3.17'
16    compileInclude group: 'org.apache.poi', name: 'poi-ooxml-schemas', version: '3.17'
17    compileInclude group: 'org.apache.poi', name: 'poi-scratchpad', version: '3.17'
18    compileInclude group: 'org.apache.poi', name: 'ooxml-schemas', version: '1.3'
19    compileInclude group: 'org.apache.poi', name: 'ooxml-security', version: '1.1'
20    compileInclude group: 'org.apache.xmlbeans', name: 'xmlbeans', version: '2.6.0'
21    compileInclude group: 'com.github.virtuald', name: 'curvesapi', version: '1.03'
22}


In my portlet´s java file, I can add:
1XSSFWorkbook 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
RE: Adding/updating external libs in DXP
April 3, 2018 5:58 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 13739

Join Date: September 1, 2006

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.
Shin Chan
RE: Adding/updating external libs in DXP
April 3, 2018 6:33 PM
Answer

Shin Chan

Rank: New Member

Posts: 6

Join Date: February 15, 2017

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
RE: Adding/updating external libs in DXP
April 3, 2018 10:58 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 13739

Join Date: September 1, 2006

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.

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!