Problems using poi with JDK 11 in a modularized application

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems using poi with JDK 11 in a modularized application

Alexander, Achim

Hello,

 

We are using apache poi to import values in our program via Excel xls and xlsx.

During the migration from Java 8 to Java 11 inclusive modularisation I encountered this problem.

The program is build in eclipse 2018-12 with maven.

 

The (hopefully) last step to do is to get poi-ooxml-4.0.1jar running.

The problem is that it requires either poi-ooxml-schemas or ooxml-schemas which both requires xmlbeans.

xmlbeans has one same named package (schemaorg_apache_xmlbeans.src) which is used in the schemas, too. This isn’t possible in a modularized java program.

 

What I did so far:

I was already able to add a module-info.jar to the jars created with jdeps.

I tried to delete the double named package (schemaorg_apache_xmlbeans.src) in the xmlbeans but obviously there are different files in this package.

Then I merged ooxml-schemas and xmlbeans to ooxml-schemas but now I get the attached exception.

 

My next approach would be to download the development sources of both projects and try to merge them, but maybe you know a better way?

 

Best regards,

 

Achim Alexander



---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Problems using poi with JDK 11 in a modularized application

kiwiwings
Hi Achim,

there's an unofficial repackage parameter for xmlbeans generation:
-repackage org.apache.xmlbeans:mybeans

We could try to provide a new XmlBeans version and/or POI schemas with custom packages,
to get rid of the name clash.

Apart of generating a dummy schema, I haven't checked further where this would have side-effects.

> I tried to delete the double named package (schemaorg_apache_xmlbeans.src) in the xmlbeans but obviously there are different files in this package.
Don't delete the schema files - the other subdirectories like "attribute","element" ... are also duplicated and needed.
I assumed merging/shading various schemas would work, but you've tested it and it didn't work.
So either we verify the shading again or try the repacking.

We just recently switched to Java 8, I'm not sure if we want a breaking change in this magnitude - best would be of course, to be really Jigsaw compatible.

Best wishes,
Andi


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: Problems using poi with JDK 11 in a modularized application

Alexander, Achim
Hi Andi,



> We could try to provide a new XmlBeans version and/or POI schemas with custom packages, to get rid of the name clash.

It would be a great help and timesaver if you can provide me with such a version. At the moment we are just reading and writing data to existing excel files, and create a simple data containing file with both, xls and xlsx. In addition there will be a docx word replacement in the near future.

I would let you know if those tasks are still working.



I was just trying to use the repackage parameter you mentioned in the ant script: <property name="repackage_arg" value="-repackage org.apache.xmlbeans:mybeans"/> but this was the result:
typeimpl.classes:
    [javac] Compiling 381 source files to L:\Apache-Poi\xmlbeans\build\classes\typeimpl
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] L:\Apache-Poi\xmlbeans\build\src\xsdschema\org\apache\xmlbeans\impl\xb\xsdschema\AppinfoDocument.java:17: error: duplicate class: mybeans.impl.xb.xsdschema.AppinfoDocument
    [javac] public interface AppinfoDocument extends mybeans.XmlObject
    [javac]        ^
    [javac] L:\Apache-Poi\xmlbeans\src\typeimpl\org\apache\xmlbeans\impl\schema\SchemaAnnotationImpl.java:28: error: cannot access AppinfoDocument
    [javac] import org.apache.xmlbeans.impl.xb.xsdschema.AppinfoDocument;
    [javac]                                             ^
    [javac]   bad source file: L:\Apache-Poi\xmlbeans\build\src\xsdschema\org\apache\xmlbeans\impl\xb\xsdschema\AppinfoDocument.java
    [javac]     file does not contain class org.apache.xmlbeans.impl.xb.xsdschema.AppinfoDocument
    [javac]     Please remove or make sure it appears in the correct subdirectory of the sourcepath.

BUILD FAILED

L:\Apache-Poi\xmlbeans\build.xml:622: Compile failed; see the compiler error output for details.



I used the zipped source distribution as I wasn't able to connect to the SVN from my working desktop. I will try it on the weekend from my private computer.

But please don't waste your time in explaining it to me when it is easier for you to build it by yourself and not necessary for me to understand. I am not even familiar with the schema topic yet.



> Don't delete the schema files - the other subdirectories like "attribute","element" ... are also duplicated and needed.

Jlink/jigsaw don't mind empty same named packages. As far as I know the only package which is causing the problem is schemaorg_apache_xmlbeans\src



> I assumed merging/shading various schemas would work, but you've tested it and it didn't work.

Don't get me wrong here. I just merged the two jar files via WinRar. As the log file wasn't attached last time, here it is as text:



XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb (schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.index) - code 0

org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb (schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.index) - code 0

                at ooxml.schemas/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1519)

                at ooxml.schemas/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:273)

                at ooxml.schemas/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:185)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

                at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

                at ooxml.schemas/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.loadTypeSystem(Unknown Source)

                at ooxml.schemas/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.<clinit>(Unknown Source)

                at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)

                at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)

                at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)

                at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:186)

                at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1105)

                at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1086)

                at java.base/java.lang.reflect.Field.get(Field.java:418)

                at ooxml.schemas/org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:771)

                at ooxml.schemas/org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument.<clinit>(Unknown Source)

                at ooxml.schemas/org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)

                at poi.ooxml/org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:86)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

                at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)

                at poi.ooxml/org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63)

                at poi.ooxml/org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:657)

                at poi.ooxml/org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:88)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:135)

                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.base/java.lang.reflect.Method.invoke(Method.java:566)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(WorkbookFactory.java:339)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook(WorkbookFactory.java:314)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:232)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:198)

                at benthin.fxclient/de.benthin.fxgui.application.DefaultWorkSheet$InternalCustomerfabricExcelHandler.getVersion(DefaultWorkSheet.java:478)

                at benthin.fxclient/de.benthin.fxgui.application.DefaultWorkSheet.checkFabricsFile(DefaultWorkSheet.java:401)

                at benthin.fxclient/de.benthin.fxgui.application.DefaultWorkSheet.lambda$start$2(DefaultWorkSheet.java:246)

                at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)

                at java.base/java.security.AccessController.doPrivileged(Native Method)

                at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)

                at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

                at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

                at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)

                at java.base/java.lang.Thread.run(Thread.java:834)



Best regards



Achim


Reply | Threaded
Open this post in threaded view
|

Re: Problems using poi with JDK 11 in a modularized application

tonterias
Please unsusbscribe me

Obtener Outlook para Android<https://aka.ms/ghei36>

________________________________
From: Alexander, Achim <[hidden email]>
Sent: Friday, January 25, 2019 2:32:53 PM
To: [hidden email]
Subject: AW: Problems using poi with JDK 11 in a modularized application

Hi Andi,



> We could try to provide a new XmlBeans version and/or POI schemas with custom packages, to get rid of the name clash.

It would be a great help and timesaver if you can provide me with such a version. At the moment we are just reading and writing data to existing excel files, and create a simple data containing file with both, xls and xlsx. In addition there will be a docx word replacement in the near future.

I would let you know if those tasks are still working.



I was just trying to use the repackage parameter you mentioned in the ant script: <property name="repackage_arg" value="-repackage org.apache.xmlbeans:mybeans"/> but this was the result:
typeimpl.classes:
    [javac] Compiling 381 source files to L:\Apache-Poi\xmlbeans\build\classes\typeimpl
    [javac] warning: [options] bootstrap class path not set in conjunction with -source 1.6
    [javac] L:\Apache-Poi\xmlbeans\build\src\xsdschema\org\apache\xmlbeans\impl\xb\xsdschema\AppinfoDocument.java:17: error: duplicate class: mybeans.impl.xb.xsdschema.AppinfoDocument
    [javac] public interface AppinfoDocument extends mybeans.XmlObject
    [javac]        ^
    [javac] L:\Apache-Poi\xmlbeans\src\typeimpl\org\apache\xmlbeans\impl\schema\SchemaAnnotationImpl.java:28: error: cannot access AppinfoDocument
    [javac] import org.apache.xmlbeans.impl.xb.xsdschema.AppinfoDocument;
    [javac]                                             ^
    [javac]   bad source file: L:\Apache-Poi\xmlbeans\build\src\xsdschema\org\apache\xmlbeans\impl\xb\xsdschema\AppinfoDocument.java
    [javac]     file does not contain class org.apache.xmlbeans.impl.xb.xsdschema.AppinfoDocument
    [javac]     Please remove or make sure it appears in the correct subdirectory of the sourcepath.

BUILD FAILED

L:\Apache-Poi\xmlbeans\build.xml:622: Compile failed; see the compiler error output for details.



I used the zipped source distribution as I wasn't able to connect to the SVN from my working desktop. I will try it on the weekend from my private computer.

But please don't waste your time in explaining it to me when it is easier for you to build it by yourself and not necessary for me to understand. I am not even familiar with the schema topic yet.



> Don't delete the schema files - the other subdirectories like "attribute","element" ... are also duplicated and needed.

Jlink/jigsaw don't mind empty same named packages. As far as I know the only package which is causing the problem is schemaorg_apache_xmlbeans\src



> I assumed merging/shading various schemas would work, but you've tested it and it didn't work.

Don't get me wrong here. I just merged the two jar files via WinRar. As the log file wasn't attached last time, here it is as text:



XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb (schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.index) - code 0

org.apache.xmlbeans.SchemaTypeLoaderException: XML-BEANS compiled schema: Could not locate compiled schema resource schemaorg_apache_xmlbeans/system/sD023D6490046BA0250A839A9AD24C443/index.xsb (schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.index) - code 0

                at ooxml.schemas/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl$XsbReader.<init>(SchemaTypeSystemImpl.java:1519)

                at ooxml.schemas/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.initFromHeader(SchemaTypeSystemImpl.java:273)

                at ooxml.schemas/org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.<init>(SchemaTypeSystemImpl.java:185)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

                at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

                at ooxml.schemas/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.loadTypeSystem(Unknown Source)

                at ooxml.schemas/schemaorg_apache_xmlbeans.system.sD023D6490046BA0250A839A9AD24C443.TypeSystemHolder.<clinit>(Unknown Source)

                at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized0(Native Method)

                at java.base/jdk.internal.misc.Unsafe.ensureClassInitialized(Unsafe.java:1042)

                at java.base/jdk.internal.reflect.UnsafeFieldAccessorFactory.newFieldAccessor(UnsafeFieldAccessorFactory.java:43)

                at java.base/jdk.internal.reflect.ReflectionFactory.newFieldAccessor(ReflectionFactory.java:186)

                at java.base/java.lang.reflect.Field.acquireFieldAccessor(Field.java:1105)

                at java.base/java.lang.reflect.Field.getFieldAccessor(Field.java:1086)

                at java.base/java.lang.reflect.Field.get(Field.java:418)

                at ooxml.schemas/org.apache.xmlbeans.XmlBeans.typeSystemForClassLoader(XmlBeans.java:771)

                at ooxml.schemas/org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument.<clinit>(Unknown Source)

                at ooxml.schemas/org.openxmlformats.schemas.drawingml.x2006.main.ThemeDocument$Factory.parse(Unknown Source)

                at poi.ooxml/org.apache.poi.xssf.model.ThemesTable.<init>(ThemesTable.java:86)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

                at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)

                at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

                at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFFactory.createDocumentPart(XSSFFactory.java:56)

                at poi.ooxml/org.apache.poi.ooxml.POIXMLFactory.createDocumentPart(POIXMLFactory.java:63)

                at poi.ooxml/org.apache.poi.ooxml.POIXMLDocumentPart.read(POIXMLDocumentPart.java:657)

                at poi.ooxml/org.apache.poi.ooxml.POIXMLDocument.load(POIXMLDocument.java:180)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:286)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:88)

                at poi.ooxml/org.apache.poi.xssf.usermodel.XSSFWorkbookFactory.createWorkbook(XSSFWorkbookFactory.java:135)

                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

                at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

                at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

                at java.base/java.lang.reflect.Method.invoke(Method.java:566)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.createWorkbook(WorkbookFactory.java:339)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.createXSSFWorkbook(WorkbookFactory.java:314)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:232)

                at poi/org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:198)

                at benthin.fxclient/de.benthin.fxgui.application.DefaultWorkSheet$InternalCustomerfabricExcelHandler.getVersion(DefaultWorkSheet.java:478)

                at benthin.fxclient/de.benthin.fxgui.application.DefaultWorkSheet.checkFabricsFile(DefaultWorkSheet.java:401)

                at benthin.fxclient/de.benthin.fxgui.application.DefaultWorkSheet.lambda$start$2(DefaultWorkSheet.java:246)

                at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)

                at java.base/java.security.AccessController.doPrivileged(Native Method)

                at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)

                at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)

                at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)

                at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)

                at java.base/java.lang.Thread.run(Thread.java:834)



Best regards



Achim


Reply | Threaded
Open this post in threaded view
|

Re: AW: Problems using poi with JDK 11 in a modularized application

kiwiwings
In reply to this post by Alexander, Achim
Hi Achim,

> But please don't waste your time in explaining it to me when it is easier for you to build it by yourself and not necessary for me to understand.

I've tried to change the schema generation via the repackage parameter, which is only available by using the org.apache.xmlbeans.impl.tool.SchemaCompiler directly, but this renames all references to standard XmlBeans classes (e.g. org.apache.xmlbeans.XmlException -> org.apache.poi.XmlException)

I'm now trying to do something similar by replacing the resource directory in the sources ... not sure if this will work out ...

Andi


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: AW: Problems using poi with JDK 11 in a modularized application

kiwiwings
In reply to this post by Alexander, Achim
Hi Achim,

for the private xmlbeans namespace in the generated re-/sources, I had to modify the XmlBeans handling of the metadata directory and change the typesystem stub/loading in POI. At least the POI tests looks good.

You find the binary of XmlBeans and the full POI schemas, including the patches for both, under:
http://people.apache.org/~kiwiwings/xmlbeans/

The ooxml-lite jar is currently missing the new private namespace files - so you would need to use the full schemas for now.

Please drop me a note how the shading worked out.

Best wishes,
Andi

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

AW: AW: Problems using poi with JDK 11 in a modularized application

Alexander, Achim
Hello Andi,



Thanks so much for your help. I managed to get it to run.



I created the module-info files with exports entries for each package which has a .class file in it.

With that I again got the error that schema files couldn't be found. Then I had a look in the description of the class.getclassloader. Here it is notices that resource files can only be loaded that way if the package is open via the module-info. I opened all packages containing the schema files. Some of them where already exports, so I changed it to opens.

That did the trick.

In our program I changed all class.getClassloader.getResource[AsStream] to class.getResource[AsStream] but with it the resources are module internal only, as long as one is not using some kind of ResourceProvider.



I guess that my previous repackage attempt where I tried to integrate xmlbeans into ooxml-schemas would have worked with opened packages, too.

But I think you still can use your work for following Jigsaw work.



Now I use modified versions of:

poi-4.0.1.jar

poi-ooxml-4.0.1.jar

ooxml-schemas-1.4.jar

xmlbeans-3.0.3.jar



Please let me know if you can use these modified versions and/or module-info files. Then I will upload them for you.



Best regards,

Achim