Thursday, March 8, 2018

How to integrate PDFBox into WildFly 11

There are no specific instructions on how to do this. Here is how I did it and it works fine for my project:

  1. Add the three main PDFBox jar files as a WildFly module. To do this you have to create a new appropriately named folder under WildFly's installation directory. Like this: <some random directory>/wildfly-11.0.0.Final/modules/system/layers/base/org/apache/pdfbox/main

  2. Then, in that directory wget the three main PDFBox jar files. Currently the latest are the  ones that also appear in the XML listing right below.

  3. Then, in the same directory, create an XML file , named module.xml, thusly:

    <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.5" name="org.apache.pdfbox">
        <resources>
            <resource-root path="pdfbox-2.0.8.jar"/>
            <resource-root path="fontbox-2.0.8.jar"/>
            <resource-root path="xmpbox-2.0.8.jar"/>
        </resources>
    
        <dependencies>
            <module name="javax.api"/>
            <module name="org.apache.commons.logging"/>
        </dependencies>
    </module>
    

  4. Now what we need is to declare the newly added pdfbox WildFly module as a global one, i.e. one that can be referenced from any deployment in our WildFly instance. To do this we need to edit our standalone.xml or domain.xml file. In the case of out pdfbox module the global declaration needs to be done under the <subsystem xmlns="urn:jboss:domain:ee:4.0"> section of the file which, for WildFly 11, it already exists and is at version 4.0. Please note that for other WildFly configurations you may need to create it altogether or you may have a different ee version number. In my case what I did is I added the following simple XML markup at the end of the section:

    <global-modules>
        <module name="org.apache.pdfbox" slot="main" />
    </global-modules>
    

  5. Restart your WildFly and you should be on!

No comments:

Post a Comment