Page 1 of 1

Running on both Java 8 and Java 11

PostPosted: Tue Jan 28, 2020 4:08 am
by arimmer
I am currently using docx4j version 3, for both XLSX and DOCX generation, compiling on Java 8.

Running on Java 8 works fine, but when I try generation of an XLSX file on Java 11 I get the following message "org.plutext.jaxb.xmldsig" does not contain ObjectFactory.class or jaxb.index.

After seeing a previous similar problem in the forum, I have checked and jaxb-xmldsig-core-1.1.1.jar is present in my classpath.

We currently have a requirement to support both Java 8 and Java 11 at runtime.

Is this possible using docx4j?

Do I need to update the version of docx4j in use?

Re: Running on both Java 8 and Java 11

PostPosted: Thu Jan 30, 2020 10:37 am
by jason
You'll find links to our current releases for Java 8 and Java 11 respectively, at https://www.docx4java.org/downloads.html

The Java 11 tree is at https://github.com/plutext/docx4j/tree/ ... ent-11.1.3

Does this answer your question?

Re: Running on both Java 8 and Java 11

PostPosted: Thu Jan 30, 2020 11:50 pm
by arimmer
Not quite - what I would like to do, if possible, is use the same jar files for both Java 8 and Java 11 - would have to be ones aimed at Java 8 as that it what we are compiling with.

So the question is really: If I install my application which uses docx4j/xlsx4j with the Java 8 jars onto Java 11 will it work to produce Word and Excel files?

Or do I need to check as part of the install process and install the appropriate versions of the docx4j/xlsx4j jars dependent on the version of Java being used on the install machine?

If the latter is the case, then I presume that it will cause us problems if/when the users upgrade from Java 8 to Java 11 as parts of our application will no longer work.

[I am currently testing with the most recent Java 8 jars, and getting messages about classes not being defined which I can see in the appropriate docx4j-openxml-objects... jars, but that could well be a problem with my classpath so I will continue with my investigations]

PS Tried to download 11.1.3 zip for testing but the link is broken, as are a number of the links to zip files of sample code (all version 11 samples, and xlsx4j version 8 samples)

Re: Running on both Java 8 and Java 11

PostPosted: Sat Feb 01, 2020 8:17 am
by jason
You may run into some hiccups running the Java 8 release on Java 11 (see closed bug https://github.com/plutext/docx4j/issues/337 ) though trying the docx4j v8.1 ConvertOutHtml sample on AdoptOpenJDK 12.0.1 (using JAXB RI) just now worked, so please do give it a go.

Regarding docx4j 11: Oops, 11.1.3 stuff can be found in https://docx4java.org/docx4j/docx4j-11.1.3/

I'll update the links now.

There are 2 obvious differences in the Java 11 jars:

(1) the bytecode version (Java 8 can't read it)
(2) presence of module-info.java files

By the way, there is a concept of "multi-release JAR", which allows you to create a single JAR that contains bytecode for several Java versions. See for example https://maven.apache.org/plugins/maven- ... lease.html We're not publishing a multi-release docx4j jar though.

Re: Running on both Java 8 and Java 11

PostPosted: Tue Feb 04, 2020 5:31 am
by arimmer
I am trying running the 8.1.4 version of docx4j on Java 11 (Adopt Open JDK 11.0.6) and I'm getting a very odd error when I try to create an .xlsx file:
Code: Select all
Exception in thread "pool-4-thread-1" java.lang.NoClassDefFoundError: org/docx4j/org/apache/xml/utils/PrefixResolver
        at java.base/java.lang.ClassLoader.defineClass1(Native Method)
        at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
        at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
        at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
        at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        at org.docx4j.jaxb.ri.NamespacePrefixMapper.getPreferredPrefix(NamespacePrefixMapper.java:74)
        at com.sun.xml.bind.v2.runtime.output.NamespaceContextImpl.declareNsUri(NamespaceContextImpl.java:155)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.startElement(XMLSerializer.java:911)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.startElement(XMLSerializer.java:266)
        at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeRoot(ClassBeanInfoImpl.java:340)
        at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsRoot(XMLSerializer.java:494)
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:328)
        at com.sun.xml.bind.v2.runtime.MarshallerImpl.marshal(MarshallerImpl.java:256)
        at javax.xml.bind.helpers.AbstractMarshallerImpl.marshal(AbstractMarshallerImpl.java:110)
        at org.docx4j.openpackaging.contenttype.ContentTypeManager.marshal(ContentTypeManager.java:930)
        at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:149)
        at org.docx4j.openpackaging.io.SaveToZipFile.save(SaveToZipFile.java:110)
....

The first line of the error seems odd to me in that it contains 'org' twice.
I downloaded the source code for docx4j 8.1.4 (zip file) and searched for PrefixResolver without success.

The 'FindJar' website suggests this class is found in xalan.jar which is included in our installation, and also definitely in our classpath.

Any ideas what the problem might be, and whether it is 'solvable'??

Thanks

Re: Running on both Java 8 and Java 11

PostPosted: Tue Feb 04, 2020 6:42 am
by jason
You need:

Code: Select all
[INFO] +- org.docx4j.org.apache:xalan-metainf:jar:8.0.0
[INFO] +- org.docx4j.org.apache:xalan-interpretive:jar:8.0.0
[INFO] |  \- org.docx4j.org.apache:xalan-serializer:jar:8.0.0


which you can find in Maven Central: https://search.maven.org/search?q=g:org ... org.apache

See further https://github.com/plutext/xalan-j/tree ... ged_Docx4j

Re: Running on both Java 8 and Java 11

PostPosted: Wed Feb 05, 2020 5:36 am
by arimmer
Thanks for the help - adding those jars got .xlsx output working, and adding commons-compress-1.19.jar got .docx output working too :)