Why documents4j run test with maven occurs error

220 Views Asked by At

I using documents4j to convert docx to PDF, while run in IDEA, all is find, but when I run test with maven or jenkins, I got an error:

java.lang.IllegalStateException: Shutdown in progress
        at java.base/java.lang.ApplicationShutdownHooks.remove(ApplicationShutdownHooks.java:82) ~[na:na]
        at java.base/java.lang.Runtime.removeShutdownHook(Runtime.java:242) ~[na:na]
        at com.documents4j.job.ConverterAdapter.deregisterShutdownHook(ConverterAdapter.java:121) ~[documents4j-util-conversion-1.1.5.jar:na]
        at com.documents4j.job.ConverterAdapter.cleanUp(ConverterAdapter.java:107) ~[documents4j-util-conversion-1.1.5.jar:na]
        at com.documents4j.job.ConverterAdapter.shutDown(ConverterAdapter.java:98) ~[documents4j-util-conversion-1.1.5.jar:na]
        at com.documents4j.job.LocalConverter.shutDown(LocalConverter.java:109) ~[documents4j-local-1.1.5.jar:na]
        at com.documents4j.job.ConverterAdapter$ConverterShutdownHook.run(ConverterAdapter.java:134) ~[documents4j-util-conversion-1.1.5.jar:na]

My pom.xml like this:

        <dependency>
            <groupId>com.documents4j</groupId>
            <artifactId>documents4j-local</artifactId>
            <version>1.1.5</version>
        </dependency>

        <dependency>
            <groupId>com.documents4j</groupId>
            <artifactId>documents4j-transformer-msoffice-word</artifactId>
            <version>1.1.5</version>
        </dependency>
2

There are 2 best solutions below

0
On

I assume that Maven runs tests in parallel (to maybe even an already running converter), what does not work. MS Word needs to run as a singleton. I do not recommend to fire up the converter within one.

0
On

Same issue and I solved it.

The problem because you create new Docx file and convert it to Pdf at the same time (in the same action).

It works well if the Docx file it exists before you convert it.