4 Replies Latest reply on Sep 6, 2012 7:54 AM by foutjo

    Classloading help - Apache FOP

    foutjo

      I'm trying to get Apache FOP to work within the JBoss AS-7.

       

      Using JBoss 5.1 I just had to add all of the jar files needed to support FOP in the JBoss/lib folder.

       

      With JBoss AS-7 it uses a different Classloading method.

       

      I used the required classloading methods when I supported XStream and the DB2 JDBC Driver.

      Both of the above only had one jar file and no dependencies.

       

      WIth Apache FOP there is one main jar file FOP.jar but also it requires the following support jar files are

      needed to use FOP:

       

      07/12/2010  09:47 PM        81,961 avalon-framework-4.2.0.jar
      07/12/2010  09:47 PM     3,318,083 batik-all-1.7.jar
      07/12/2010  09:47 PM        83,613 commons-io-1.3.1.jar
      07/12/2010  09:47 PM        38,015 commons-logging-1.0.4.jar
      05/24/2012  01:28 PM     3,079,811 fop.jar
      07/12/2010  09:47 PM       188,993 serializer-2.7.0.jar
      07/12/2010  09:47 PM     3,078,601 xalan-2.7.0.jar
      07/12/2010  09:47 PM     1,203,860 xercesImpl-2.7.1.jar
      07/12/2010  09:47 PM       194,354 xml-apis-1.3.04.jar
      07/12/2010  09:47 PM        85,686 xml-apis-ext-1.3.04.jar
      07/12/2010  09:47 PM       569,113 xmlgraphics-commons-1.4.jar

       

      When supporting XStream I added support in the /modules structure of JBOSS along

      with the following module.xml file.

       

      <module name="com.thoughtworks.xstream">

          <dependencies>

                  <module name="javax.api"/>

          </dependencies>

         <resources>

               <resource-root path="xstream-1.4.1.jar"/>

         </resources></module>

       

       

      Could someone tell me how I would support the FOP.jar along with all of its dependent jar files?

       

       

      Any help on this is greatly appreciated.

       

      Thanks.

        • 1. Re: Classloading help - Apache FOP
          guinotphil

          Hi,

           

          If I understand you wanna deploy FOP as a JBoss module ?

           

          Here are the modules that I set up to be able to use FOP and Batik under AS 7.

           

          <?xml version="1.0" encoding="UTF-8"?>

          <module xmlns="urn:jboss:module:1.1" name="org.apache.xmlgraphics">

              <resources>

                  <resource-root path="xmlgraphics-commons-1.4.jar"/>

                  <resource-root path="fop-0.94.jar"/>

                  <resource-root path="batik-xml-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-util-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-ttf2svg-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-transcoder-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-swing-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-svgpp-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-svggen-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-svg-dom-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-squiggle-ext-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-squiggle-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-slideshow-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-script-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-rasterizer-ext-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-rasterizer-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-parser-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-gvt-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-gui-util-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-extension-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-dom-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-css-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-codec-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-bridge-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-awt-util-1.8pre-11-03-22.jar"/>

                  <resource-root path="batik-anim-1.8pre-11-03-22.jar"/>

                  <!-- Insert resources here -->

              </resources>

           

              <dependencies>

                  <!-- Don't use javax.api but import the needed modules.... -->

                  <module name="javax.imageio.api"/>

                  <module name="javax.xml.api" />

                  <module name="javax.xml.stream.api" />

                  <module name="org.xml.sax" />

                  <!-- ... as we need to import Apache's dom api ! -->

                  <module name="org.w3c.dom" slot="apache"/>

                  <module name="org.w3c.css.sac"/>

           

                  <module name="org.apache.avalon"/>

                  <module name="org.apache.commons.io"/>

                  <module name="org.apache.commons.logging"/>

                  <module name="org.apache.xalan"/>

                  <module name="org.apache.xerces"/>

           

                  <module name="org.mozilla.rhino" slot="batik"/>

              </dependencies>

           

          </module>

           

           

          And so the following additional apache modules are needed:

           

          Avalon

          <module xmlns="urn:jboss:module:1.1" name="org.apache.avalon">

                <resources>

                  <resource-root path="avalon-logkit-2.2.1.jar"/>

                  <resource-root path="avalon-framework-impl-4.3.1.jar"/>

                  <resource-root path="avalon-framework-api-4.3.1.jar"/>

                  <!-- Insert resources here -->

              </resources>

                <dependencies>

                   <module name="javax.api" />

                   <module name="org.apache.commons.logging"/>

                   <module name="org.apache.log4j"/>

              </dependencies>

          </module>

           

          Batik's fork of Rhino:

          <module xmlns="urn:jboss:module:1.1" name="org.mozilla.rhino" slot="batik"><!-- patched version for batik -->

              <resources>

                  <resource-root path="batik-js-1.8pre-11-03-22.jar"/>

                  <!-- Insert resources here -->

              </resources>

              <dependencies>

              </dependencies>

          </module>

           

          After that, there's a trick with Apache's own implementation of w3c classes. Some interfaces such as  org.w3c.dom.events.Event are different in apache's libs to the JRE versions. And it seems to cause a lot of problems to people who use apache and non-apache libs that relies on those classes. All I could do is put them in a specific module and let thme be used only by the xmlgraphic module. But this may still cause some linkage errors if instance of those interfaces are casted into the JVM interface outside this module..

          So, instead of being dependent to javax.api, I added dependencies to:

          javax.xml.stream.api (already present in AS7.1.1.Final)

          javax.xml.api:

          <module xmlns="urn:jboss:module:1.1" name="javax.xml.api">

              <dependencies>

                  <system export="true">

                      <paths>

                          <path name="javax/xml"/>

                          <path name="javax/xml/datatype"/>

                          <path name="javax/xml/namespace"/>

                          <path name="javax/xml/parsers"/>

                          <path name="javax/xml/transform"/>

                          <path name="javax/xml/transform/dom"/>

                          <path name="javax/xml/transform/sax"/>

                          <path name="javax/xml/transform/stax"/>

                          <path name="javax/xml/transform/stream"/>

                          <path name="javax/xml/validation"/>

                          <path name="javax/xml/xpath"/>

                      </paths>

                  </system>

                  <module name="javax.xml.stream.api" />

                  <module name="org.xml.sax" />

                  <module name="org.w3c.dom" />

              </dependencies>

          </module>

           

          org.xml.sax

          <module xmlns="urn:jboss:module:1.1" name="org.xml.sax">

              <dependencies>

                  <system export="true">

                      <paths>

                          <path name="org/xml/sax"/>

                          <path name="org/xml/sax/ext"/>

                          <path name="org/xml/sax/helpers"/>

                      </paths>

                  </system>

              </dependencies>

          </module>

           

           

          and create two version of org.w3c.dom

          • main slot:

          <module xmlns="urn:jboss:module:1.1" name="org.w3c.dom">

              <resources>

                  <resource-root path="dom-svg-1.1.20110816.jar"/>

                  <resource-root path="dom-validation-1.0.20040127.jar"/>

                  <!-- Import W3C's official Java bindings -->

              </resources>

           

              <dependencies>

                  <!-- use JDK's impl of course -->

                  <system export="true">

                      <paths>

                          <path name="org/w3c/dom"/>

                          <path name="org/w3c/dom/bootstrap"/>

                          <path name="org/w3c/dom/css"/>

                          <path name="org/w3c/dom/events"/>

                          <path name="org/w3c/dom/html"/>

                          <path name="org/w3c/dom/ls"/>

                          <path name="org/w3c/dom/ranges"/>

                          <path name="org/w3c/dom/stylesheets"/>

                          <path name="org/w3c/dom/traversal"/>

                          <path name="org/w3c/dom/views"/>

                          <path name="org/w3c/dom/xpath"/>

                      </paths>

                  </system>

              </dependencies>

          </module>

           

          Those jars are built from the sources available on w3c's website:

          http://www.w3.org/TR/2011/REC-SVG11-20110816/java.html

          http://www.w3.org/TR/DOM-Level-3-Val/java-binding.html

           

          • apache slot:

          <!-- This is Apache's bindings of dom classes -->

          <!-- They are different concernant the events and svg package -->

          <!-- Mixing use of Apache interfaces and standard interfaces may lead to Linkage Errors -->

          <module xmlns="urn:jboss:module:1.1" name="org.w3c.dom" slot="apache">

              <resources>

                  <resource-root path="xml-apis-ext-1.3.04-dom.jar"/>

                  <resource-root path="batik-ext-1.8pre-11-03-22.jar"/>

                  <resource-root path="dom-validation-1.0.20040127.jar"/>

                  <!-- Import Apache's libraries -->

              </resources>

           

           

              <dependencies>

                  <!-- use JDK's impl, except for events package -->

                  <system export="true">

                      <paths>

                          <path name="org/w3c/dom"/>

                          <path name="org/w3c/dom/bootstrap"/>

                          <path name="org/w3c/dom/css"/>

                          <!-- path name="org/w3c/dom/events"/ -->

                          <path name="org/w3c/dom/html"/>

                          <path name="org/w3c/dom/ls"/>

                          <path name="org/w3c/dom/ranges"/>

                          <path name="org/w3c/dom/stylesheets"/>

                          <path name="org/w3c/dom/traversal"/>

                          <path name="org/w3c/dom/views"/>

                          <path name="org/w3c/dom/xpath"/>

                      </paths>

                  </system>

              </dependencies>

          </module>

          with the apache builds that are to be found in maven central.

           

           

          And finally, you also need the image IO API as you can't import javax.api :

          create javax.imageio.api

          <module xmlns="urn:jboss:module:1.1" name="javax.imageio.api">

              <dependencies>

                  <system export="true">

                      <paths>

                          <path name="javax/imageio"/>

                          <path name="javax/imageio/event"/>

                          <path name="javax/imageio/metadata"/>

                          <path name="javax/imageio/plugins/bmp"/>

                          <path name="javax/imageio/plugins/jpeg"/>

                          <path name="javax/imageio/spi"/>

                          <path name="javax/imageio/stream"/>

                      </paths>

                  </system>

              </dependencies>

          </module>

           

          Then, you can also edit the javax.api module, to remove the lines

                          <path name="javax/imageio"/>

                          <path name="javax/imageio/event"/>

                          <path name="javax/imageio/metadata"/>

                          <path name="javax/imageio/plugins/bmp"/>

                          <path name="javax/imageio/plugins/jpeg"/>

                          <path name="javax/imageio/spi"/>

                          <path name="javax/imageio/stream"/>

                          <path name="javax/xml"/>

                          <path name="javax/xml/datatype"/>

                          <path name="javax/xml/namespace"/>

                          <path name="javax/xml/parsers"/>

                          <path name="javax/xml/stream"/>

                          <path name="javax/xml/stream/events"/>

                          <path name="javax/xml/stream/util"/>

                          <path name="javax/xml/transform"/>

                          <path name="javax/xml/transform/dom"/>

                          <path name="javax/xml/transform/sax"/>

                          <path name="javax/xml/transform/stax"/>

                          <path name="javax/xml/transform/stream"/>

                          <path name="javax/xml/validation"/>

                          <path name="javax/xml/xpath"/>

                          <path name="org/w3c/dom"/>

                          <path name="org/w3c/dom/bootstrap"/>

                          <path name="org/w3c/dom/css"/>

                          <path name="org/w3c/dom/events"/>

                          <path name="org/w3c/dom/html"/>

                          <path name="org/w3c/dom/ranges"/>

                          <path name="org/w3c/dom/stylesheets"/>

                          <path name="org/w3c/dom/traversal"/>

                          <path name="org/w3c/dom/ls"/>

                          <path name="org/w3c/dom/views"/>

                          <path name="org/w3c/dom/xpath"/>

                          <path name="org/xml/sax"/>

                          <path name="org/xml/sax/ext"/>

                          <path name="org/xml/sax/helpers"/>

          But add the dependencies:

                  <module name="javax.imageio.api" export="true" />

                  <module name="javax.xml.api" export="true" />

                  <module name="javax.xml.stream.api" export="true" />

                  <module name="org.xml.sax" export="true" />

                  <module name="org.w3c.dom" export="true" />


           

          If you want to integrate it with Sun's JAI image IO you may also want to look here: https://community.jboss.org/message/717412#717412

           

          Oh... and by the way, you need here the separate batik jars. I can remember that in the build ant task of apache's batik 1.8 there's a bug and one of the jar misses a package wich is included in batik-all however. Please check that you still got all the classes in the separate jars before copying them into the modules.

           

          Now, just import the org.apache.xmlgraphics module in you jboss-deployment-structure.xml and you should be able to use FOP and Batik

          • 2. Re: Classloading help - Apache FOP
            foutjo

            Hi Quinotphil,

             

            Thanks so much for you input on my issue with classloading to support Apache FOP.

             

            After reading all of the info that you posted I have to admit that I am still very confused on what I have to do to support FOP.

            I don't have a clear understanding of what and how jar files and packages are supported.

             

            I am hoping that if I take baby steps it will help get a better understanting on what I have to do.

             

            As I mentioned earlier I was able to get FOP working with JBOSS 5.1 by adding all of the following .jar files to the JBOSS 5.1 /lib folder:

            ** These jar files were included in the Apache FOP1.0 binary download file. 

             

              fop.jar

              avalon-framework-4.2.0.jar

              batik-all-1.7.jar

              commons-io-1.3.1.jar

              commons-logging-1.0.4.jar

              serializer-2.7.0.jar

              xalan-2.7.0.jar

              xercesImpl-2.7.1.jar

              xml-apis-1.3.04.jar

              xml-apis-ext-1.3.04.jar

              xmlgraphics-commons-1.4.jar 

             

            Lets start with the first org.apache.xmlgraphics module definition:

             

            <?xml version="1.0" encoding="UTF-8"?>

            <module xmlns="urn:jboss:module:1.1" name="org.apache.xmlgraphics">

                <resources>

                    <resource-root path="xmlgraphics-commons-1.4.jar"/>

                    <resource-root path="fop-0.94.jar"/>

                    <resource-root path="batik-xml-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-util-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-ttf2svg-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-transcoder-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-swing-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-svgpp-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-svggen-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-svg-dom-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-squiggle-ext-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-squiggle-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-slideshow-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-script-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-rasterizer-ext-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-rasterizer-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-parser-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-gvt-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-gui-util-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-extension-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-dom-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-css-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-codec-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-bridge-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-awt-util-1.8pre-11-03-22.jar"/>

                    <resource-root path="batik-anim-1.8pre-11-03-22.jar"/>

                    <!-- Insert resources here -->

                </resources>

             

                <dependencies>

                    <!-- Don't use javax.api but import the needed modules.... -->

                    <module name="javax.imageio.api"/>

                    <module name="javax.xml.api" />

                    <module name="javax.xml.stream.api" />

                    <module name="org.xml.sax" />

                    <!-- ... as we need to import Apache's dom api ! -->

                    <module name="org.w3c.dom" slot="apache"/>

                    <module name="org.w3c.css.sac"/>

             

                    <module name="org.apache.avalon"/>

                    <module name="org.apache.commons.io"/>

                    <module name="org.apache.commons.logging"/>

                    <module name="org.apache.xalan"/>

                    <module name="org.apache.xerces"/>

             

                    <module name="org.mozilla.rhino" slot="batik"/>

                </dependencies>

             

            </module>

             

             

            1.  Create a new folder under modules.org.apache named "xmlgraphics".

            2.  Create the module.xml file with the info from above.

            3.  Copy the xmlgraphics-commons-1.4.jar from the FOP download lib folder to this new folder.

            4.  Do I need to copy other jar files into this folder or should the xmlgraphics.jar be the only one in this folder?

            5.  The resouces also reference many batik.....jar files.  When I explode the current batik-all-1.7.jar that I got

                 from the FOP download zip file I do not see any of the batik jar files that you refenece above. 

                 Am I missing something?

             

            I want to understand how to set this up but I just don't get it.

             

            Thanks again for any additional help that you might be able to share with me.

            • 3. Re: Classloading help - Apache FOP
              guinotphil

              You can use the batik-all.jar instead all the small batik jars, but you'll probable end with trouble with the dom classes.

               

              You can get the batik distribution here: http://xmlgraphics.apache.org/batik/download.cgi and it includes both batik-all.jar and the different jars of the distribution. However, they may be a bit different from my exemple, since the last stable version is batik-1.7 and I used batik-1.8pre-11-03-22

              • 4. Re: Classloading help - Apache FOP
                foutjo

                I was able to get FOP to work.

                 

                Would not have been able to do this without your help quinotphil.

                 

                Thanks!!!