Page 1 of 1

Alfresco 5.0 and DocX4J

PostPosted: Thu Feb 12, 2015 11:10 pm
by andreas
Hello DocX4J forum,
We are working on a project were we need to generate docx documents inside Alfresco. In order to do so we use docx4j, so this dependency is added to our repo pom.xml file

Code: Select all
<dependency>
   <groupId>org.docx4j</groupId>
   <artifactId>docx4j</artifactId>
   <version>3.2.0</version>
</dependency>

However, adding this depenency results in a runtime error in Alfresco when using basic functionality (Alfresco is deployed inside the web-container tomcat)
The problem was related to the dependencies of docx4j. A newer version of the artifacts fop 1.1 and xml-graphics-commons 1.5 from the group org.apache.xmlgraphics is required and provided by docx4j, so adding the following averted the problem.

Code: Select all
<dependency>
   <groupId>org.docx4j</groupId>
   <artifactId>docx4j</artifactId>
   <version>3.2.0</version>
   <exclusions>
    <exclusion>
      <groupId>org.apache.xmlgraphics</groupId>
      <artifactId>xmlgraphics-commons</artifactId>   
   </exclusion>
   <exclusion>
      <groupId>org.apache.xmlgraphics</groupId>
      <artifactId>fop</artifactId>
   </exclusion>
  </exclusions>
</dependency>

Obviously this leaves the docx4j in a somewhat far from optimal position and not suprisingly generation of new documents results in runtime exceptions...
Do you have any recommendation, experiences or solution in this matter ?

At the moment we are trying to rebuild docx4j with shaded dependencies to org.apache via the mvn plugin http://maven.apache.org/plugins/maven-s ... ation.html
Hope to hear from you
Andreas

Re: Alfresco 5.0 and DocX4J

PostPosted: Sat Feb 14, 2015 5:35 pm
by jason
Please see attached docx for a comparison of jar versions and some comments.

I would try:

- using Alfresco's version of FOP (0.94) and batik

- replacing Alfresco's xml-graphics-commons with 1.5

Feel free to paste the exceptions here for further thoughts..

Re: Alfresco 5.0 and DocX4J

PostPosted: Thu Feb 19, 2015 7:18 pm
by andreas
Hello Jason,
It worked! It seems to work, but more in depth testing would of course be ideal.
This is the dependency import in Alfresco.

Code: Select all
<dependency>
         <groupId>org.docx4j</groupId>
         <artifactId>docx4j</artifactId>
         <version>3.2.1</version>
         <exclusions>
            <exclusion>
               <groupId>org.apache.xmlgraphics</groupId>
               <artifactId>fop</artifactId>
            </exclusion>
         </exclusions>
      </dependency>

      <!-- This is the version of FOP provided by Alfresco. Docx4j dependency -->
      <dependency>
         <groupId>org.apache.xmlgraphics</groupId>
         <artifactId>fop</artifactId>
         <version>0.94</version>
         <scope>test</scope>
      </dependency>


and then we manual delete the xmĺgraphics-common version 1.2 provided by Alfresco. In the end Alfresco keeps fop 0.94 but gets xmlgraphics-common 1.5. Unit and integration tests are also tested against fop 0.94.

Thank you for all the help

Re: Alfresco 5.0 and DocX4J

PostPosted: Thu Feb 19, 2015 8:15 pm
by jason
That's good to hear :-)

You might suggest to Alfresco that they upgrade to xmlgraphics-common 1.5, and FOP 1.1 (noting that these upgrades can be done independently)

I'll look at bumping the versions of some of the older docx4j deps.

Re: Alfresco 5.0 and DocX4J

PostPosted: Sat Feb 21, 2015 2:57 am
by andreas
okay, we are almost there...
antlr-runtime needs to be excluded as well. Starting a search in Alfresco gave this exception

Code: Select all
Caused by: java.lang.NoSuchMethodError: org.alfresco.repo.search.impl.parsers.FTSLexer.getEOFToken()Lorg/antlr/runtime/Token;
   at org.alfresco.repo.search.impl.parsers.FTSLexer.nextTokenImpl(FTSLexer.java:133)


So we added this exclusion
Code: Select all
<exclusion>
   <groupId>org.antlr</groupId>
   <artifactId>antlr-runtime</artifactId>
</exclusion>

Re: Alfresco 5.0 and DocX4J

PostPosted: Wed May 31, 2017 3:55 am
by fwu
hello,

Sorry for returning to this old post, but im using Alfresco 4.2.f and Im getting the follwoing error when trying to run Alfresco (Alfresco will not work after this error, maybe because the info says: Shutting down log4j):

Code: Select all
SEVERE: Exception sending context initialized event to listener instance of class org.alfresco.web.app.ContextLoaderListener
java.lang.NoSuchMethodError: org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
   at org.apache.commons.logging.impl.SLF4JLocationAwareLog.error(SLF4JLocationAwareLog.java:225)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:220)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
   at org.alfresco.web.app.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:63)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
   at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
   at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
   at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073)
   at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
   at java.util.concurrent.FutureTask.run(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)


As far as I understood Alfresco 4.2.f is using slf4j-api-1.5.11.jar. However, docx4j 3.2.1 jars is using slf4j-api-1.7.5.

I tried to exclude slf4j in the dependecy import of doc4j like this, but I get the same error.

Code: Select all
<exclusion>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
</exclusion>


I also tried to add a dependecy like this, but also without luck.

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.11</version>
</dependency>

What can be done?

thank you!

Re: Alfresco 5.0 and DocX4J

PostPosted: Thu Jun 01, 2017 4:18 am
by fwu
hello,

I realize that if I manually replace the slf4j-api-1.5.11.jar by the slf4j-api-1.7.5.jar, Alfresco seems to work right. I then made some tests and I found one jar that is being deployed by my application (that also deploys docx4j): jcl-over-slf4j-1.7.5.jar. This is the jar that is throwing errors regarding slf4j. The strange is that this jar should need the sl4j-api 1.7.5 ... exactaly the one I deployed to Alfresco replacing the 1.1.11 version. So, jcl-over-slf4j-1.7.5.jar doesnt work with slf4j-api-1.7.5.jar?

Code: Select all
java.lang.AbstractMethodError: org.slf4j.impl.Log4jLoggerAdapter.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V
   at org.apache.commons.logging.impl.SLF4JLocationAwareLog.trace(SLF4JLocationAwareLog.java:107)
   at org.apache.myfaces.webapp.StartupServletContextListener.initFaces(StartupServletContextListener.java:76)
   at org.apache.myfaces.webapp.StartupServletContextListener.contextInitialized(StartupServletContextListener.java:65)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4973)
   at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5467)
   at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:632)
   at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1073)
   at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1857)
   at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
   at java.util.concurrent.FutureTask.run(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at java.lang.Thread.run(Unknown Source)