FlowingCode / GridExporterAddon

Other
10 stars 8 forks source link

export to PDF it fails when you are using vaadin 24.0.5 #57

Closed cqrendo closed 5 months ago

cqrendo commented 1 year ago

Using the gridExporter (https://vaadin.com/directory/component/grid-exporter-add-on ) in V24 , when you try to export a PDF you get the following error:

Exception in thread "Thread-21" java.lang.NoClassDefFoundError: javax/xml/bind/ValidationEventHandler
at com.flowingcode.vaadin.addons.gridexporter.PdfInputStreamFactory$1.run(PdfInputStreamFactory.java:64)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.ValidationEventHandler
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 2 more
javier-godoy commented 1 year ago

Hello.

The error seems to be related to the renaming of javax.xml.bind to jakarta.xml.bind. However, it's not clear how it affects the add-on. The examples at https://addonsv24.flowingcode.com/gridexporter work properly.

The add-on uses JAXB, and has a dependency with an old version of docx4j, which in turns depends on jaxb-runtime 2.3.2. On the other hand, the demo at https://addonsv24.flowingcode.com/ happens to use jaxb-runtime 4.0.1 instead, and the add-on works on that environment.

Please attach a reproducible example so that we can investigate the issue.

mlopezFC commented 1 year ago

We were able to reproduce this issue in the addons demo. The problem is exactly as @javier-godoy described. The add-on uses JAXB, and has a dependency with an old version of docx4j, which in turns depends on jaxb-runtime 2.3.2. Our demo at https://addonsv24.flowingcode.com/ happens to use jaxb-runtime 4.0.1 instead, and we thought the add-on was working on that environment, but we realized that the pdf export was not working. We solved the issue by adding the following to our demos:

    <dependencyManagement>
        <dependencies>
...
            <dependency>
                <groupId>org.glassfish.jaxb</groupId>
                <artifactId>jaxb-runtime</artifactId>
                <version>2.3.2</version>
            </dependency>
            <dependency>
                <groupId>jakarta.xml.bind</groupId>
                <artifactId>jakarta.xml.bind-api</artifactId>
                <version>2.3.2</version>
            </dependency>
            <dependency>
                <groupId>jakarta.activation</groupId>
                <artifactId>jakarta.activation-api</artifactId>
                <version>1.2.2</version>
            </dependency>
        </dependencies>
    </dependencyManagement>

With a similar approach the issue can be fixed on some projects, but if the project is using the newer versions of those dependencies then it won't work. So we're leaving this ticket opened until we find a better solution, but this can be used as a temporal workaround for certain projects.

mlopezFC commented 5 months ago

Closing this ticket given that we couldn't find a better solution.