Page 1 of 1

Docx4J.pdfViaDocuments4jLocal() searches for unknown class

PostPosted: Thu Jul 01, 2021 10:51 pm
by Lars
Hello.

I'm running version 8.2.8 and tried the local conversion by following the getting started guide.

I added the the dependencies:
Code: Select all
  // Docx4J
  implementation 'org.docx4j:docx4j-core:8.2.8'
  implementation 'org.docx4j:docx4j-openxml-objects:8.2.8'
  implementation 'org.docx4j:docx4j-openxml-objects-pml:8.2.8'
  implementation 'org.docx4j:docx4j-openxml-objects-sml:8.2.8'
  // MOXy docx-JAXB Impl
  implementation 'org.docx4j:docx4j-JAXB-MOXy:8.2.8'
  implementation 'org.docx4j:docx4j-documents4j-local:8.2.8'


Docx4j itself works fine.. but PDF converting not at all.

The method Docx4J.pdfViaDocuments4jLocal(); internally looks for the class "org.docx4j.convert.out.documents4j.local.Documents4jLocalExporter" but this class is nowhere to be found in the class path. I also did not find another dependency on maven that is missing.

What dependency is missing? Where can i find it?

Kind regards
Lars

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Sat Jul 03, 2021 5:17 pm
by jason
Hi Lars

Thanks for the pickup. In the meantime, you can invoke Documents4jLocalServices directly; see the examples at https://github.com/plutext/docx4j/tree/ ... ts4j/local

cheers .. Jason

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Sun Jul 11, 2021 1:39 am
by Lars
Hi Jason.
Thank you for you replay.

Unfortunately this does not work eigther.

I'm doing this now:
Code: Select all
      Documents4jLocalServices exporter = new Documents4jLocalServices();
      exporter.export(wordprocessingMlPackage, targetStream);


This produces this Exception when invoking the new Documents4jLocalServices() C'tor:
Code: Select all
java.lang.IllegalStateException: class com.documents4j.conversion.msoffice.MicrosoftWordBridge could not be created by a (File, long, TimeUnit) constructor
with cause:
java.lang.reflect.InvocationTargetException
class com.documents4j.conversion.msoffice.MicrosoftWordBridge could not be created by a (File, long, TimeUnit) constructor

java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;Ljava/lang/Object;)V


For me it looks like the code is using:
com.google.common.base.Preconditions
but may be it should use:
org.docx4j.com.google.common.base.Preconditions

Or do I just have the wrong version?

the import is in this class:
Code: Select all
package com.documents4j.job;
[..]
import static com.google.common.base.Preconditions.checkState;
[..]
public abstract class ConverterAdapter implements IConverter {
[..]
    private static File makeTemporaryFolder(File baseFolder) {
        File tempFileFolder = new File(baseFolder, UUID.randomUUID().toString());
        checkState(tempFileFolder.mkdir(), String.format("Cannot create folder: %s", tempFileFolder));
        return tempFileFolder;
    }
[..]
}


And indeed, in google-collections 1.0 there is no methode checkArgument(String,String,Object);

Is this the problem? Which version of google collection/guava should i use?


Can you please help?

kind regards
Lars

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Mon Jul 12, 2021 12:39 pm
by jason
mvn dependency:tree reports:

Code: Select all
[INFO] |  +- com.documents4j:documents4j-local:jar:1.1.3:compile
[INFO] |  |  +- com.documents4j:documents4j-api:jar:1.1.3:compile
[INFO] |  |  +- com.documents4j:documents4j-transformer:jar:1.1.3:compile
[INFO] |  |  +- com.documents4j:documents4j-util-conversion:jar:1.1.3:compile
[INFO] |  |  |  \- javax.activation:activation:jar:1.1.1:compile
[INFO] |  |  +- com.google.guava:guava:jar:28.1-jre:compile
[INFO] |  |  |  +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] |  |  |  +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] |  |  |  +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] |  |  |  +- com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] |  |  |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.18:compile
[INFO] |  |  \- org.zeroturnaround:zt-exec:jar:1.11:compile
[INFO] |  \- com.documents4j:documents4j-transformer-msoffice-word:jar:1.1.3:compile
[INFO] |     +- com.documents4j:documents4j-transformer-msoffice-base:jar:1.1.3:compile
[INFO] |     +- com.documents4j:documents4j-transformer-api:jar:1.1.3:compile
[INFO] |     |  \- com.documents4j:documents4j-util-all:jar:1.1.3:compile
[INFO] |     \- com.documents4j:documents4j-util-transformer-process:jar:1.1.3:compile


Do you have those jars?

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Tue Jul 13, 2021 2:37 am
by Lars
Hi Jason.

Yes, we got all of this.

The problem is deeper in the class path.

We have dependenciey that have google-collections as a dependency. Docx4J need a similar class but in a newer version provided by guava.

The problem is that in runtime the wildfly chooses the first match it finds in the class path and that is Preconditions class from google-collections not from google-guava. I do not know why wildfly is working like that because it brings guava on board so from the specification it should load guava first. I already tried to specify the dependency in the ear, but also did not work.

Do you thing it is possible to provide a version of docx4j where this check could be optional.

I see no other way to fix this in our environment :(

kind regards
Lars

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Tue Jul 13, 2021 7:45 pm
by jason
Hi Lars

package com.documents4j.job is part of documents4j, not docx4j

https://github.com/documents4j/documents4j

I see they have just release v1.1.7, I guess that if anything, this uses a still newer guava.

Can your other dependency be made to use more recent google stuff?

Before you go to too much effort here, I take it you have satisfied yourself that documents4j does what you want (ie in a dev environment without the other jars causing issues).

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Tue Jul 13, 2021 8:14 pm
by Lars
Hi Jason.

The Unit-Test results are looking great, it just not runs on the server.
We definetly want to use it like this.

>>> Can your other dependency be made to use more recent google stuff?
No. There are also 3rd Party, we can not update them without a much bigger effort beacause we are talking about "old" core features like sqlserver connectors and those things.

Are you suggesting to download and change the documents4j code?

kind regards
Lars

Re: Docx4J.pdfViaDocuments4jLocal() searches for unknown cla

PostPosted: Wed Jul 14, 2021 9:24 am
by jason
Altering the documents4j code is one approach; you could then make a PR.

But first, consider https://github.com/plutext/docx4j/tree/ ... s4j-remote

With this, you could run documents4j server in a separate webapp in wildfly, and hopefully avoid the jar hell you are experiencing (I haven't checked).

Sample code is at https://github.com/plutext/docx4j/tree/ ... s4j-remote