{"id":253,"date":"2013-11-28T13:01:37","date_gmt":"2013-11-28T03:01:37","guid":{"rendered":"http:\/\/www.docx4java.org\/blog\/?p=253"},"modified":"2013-11-28T13:09:24","modified_gmt":"2013-11-28T03:09:24","slug":"docx4j-3-0-and-maven","status":"publish","type":"post","link":"https:\/\/www.docx4java.org\/blog\/2013\/11\/docx4j-3-0-and-maven\/","title":{"rendered":"docx4j 3.0 and Maven"},"content":{"rendered":"<p><a href=\"http:\/\/www.docx4java.org\/blog\/2011\/10\/hello-maven-central\/\">blog\/2011\/10\/hello-maven-central\/<\/a> walks you through the basics of using docx4j in an Eclipse project with the help of m2eclipse.<\/p>\n<p>This post is about the different ways you can set up <strong>docx4j 3.0<\/strong> with the help of Maven.<\/p>\n<p>We&#8217;ll be using the following skeleton pom.xml:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n&lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd&quot;&gt;\r\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\r\n\t\t\r\n\t&lt;groupId&gt;your.group&lt;\/groupId&gt;\r\n\t&lt;artifactId&gt;your.artifactp&lt;\/artifactId&gt;\r\n\t&lt;name&gt;nameless&lt;\/name&gt;\r\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\r\n\t&lt;description&gt;\r\n\t\tsome description\r\n\t&lt;\/description&gt;\r\n\r\n\r\n\t&lt;properties&gt;\r\n\t\t&lt;project.build.sourceEncoding&gt;UTF-8&lt;\/project.build.sourceEncoding&gt;\r\n\t&lt;\/properties&gt;\r\n\r\n\t&lt;build&gt;\r\n\t\t&lt;plugins&gt;\r\n\t\t\t&lt;plugin&gt;\r\n\t\t\t\t&lt;groupId&gt;org.apache.maven.plugins&lt;\/groupId&gt;\r\n\t\t\t\t&lt;artifactId&gt;maven-dependency-plugin&lt;\/artifactId&gt;\r\n\t\t\t\t&lt;version&gt;2.0&lt;\/version&gt;\r\n\t\t\t&lt;\/plugin&gt;\r\n\t\t&lt;\/plugins&gt;\r\n\t&lt;\/build&gt;\r\n\t\r\n\t&lt;dependencies&gt;\r\n\t\r\n\t\t&lt;!-- dependencies go here --&gt;\r\n\r\n\t\t\t\t \t\r\n\t&lt;\/dependencies&gt;\r\n\r\n&lt;\/project&gt;\r\n<\/pre>\n<p><strong>Adding the core dependency<\/strong><\/p>\n<p>To use docx4j, including its LGPL <strong>XHTML import<\/strong> capability, just include the following dependency in your pom.xml:<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.docx4j&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;docx4j-ImportXHTML&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;3.0.0&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n<\/pre>\n<div>That&#8217;ll drag in docx4j, and all the other dependencies (you should be able to see then in Eclipse under Maven Dependencies, or by running <strong>mvn dependency:tree <\/strong>at a command prompt).<\/div>\n<div>If you <strong>don&#8217;t want <\/strong>the XHTML import stuff, just use:<\/div>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.docx4j&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;docx4j&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;3.0.0&lt;\/version&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n<\/pre>\n<div>(You should consider adding a <a href=\"https:\/\/github.com\/plutext\/docx4j\/blob\/master\/src\/samples\/_resources\/docx4j.properties\"><strong>docx4j.properties<\/strong><\/a> to your classpath)<\/div>\n<div><strong>Logging<\/strong><\/div>\n<div>Both of the above default to using <strong>log4j<\/strong>. \u00a0If you are happy with log4j, you&#8217;ll want a log4j.xml file unless you already have it on your classpath. \u00a0If you don&#8217;t, you can configure\u00a0<a href=\"https:\/\/github.com\/plutext\/docx4j\/blob\/master\/src\/samples\/_resources\/log4j.xml\">https:\/\/github.com\/plutext\/docx4j\/blob\/master\/src\/samples\/_resources\/log4j.xml<\/a> to suit.<\/div>\n<div>If you want to use something other than log4j for logging, well you can, since docx4j uses <strong>slf4j<\/strong>.<\/div>\n<div>First you need to exclude the log4j stuff.<\/div>\n<div>\n<div><span style=\"white-space: pre;\"><\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\r\n\r\n\t\t&lt;dependency&gt;\r\n\t\t\t&lt;groupId&gt;org.docx4j&lt;\/groupId&gt;\r\n\t\t\t&lt;artifactId&gt;docx4j-ImportXHTML&lt;\/artifactId&gt;\r\n\t\t\t&lt;version&gt;3.0.0&lt;\/version&gt;\r\n\t\t\t&lt;exclusions&gt;\r\n\t\t\t\t&lt;exclusion&gt;\r\n\t\t\t\t\t  &lt;groupId&gt;org.slf4j&lt;\/groupId&gt;\r\n\t\t\t\t\t  &lt;artifactId&gt;slf4j-log4j12&lt;\/artifactId&gt;\r\n\t\t\t\t&lt;\/exclusion&gt;\r\n\t\t\t\t&lt;exclusion&gt;\r\n\t\t\t\t\t&lt;groupId&gt;log4j&lt;\/groupId&gt;\r\n\t\t\t\t\t&lt;artifactId&gt;log4j&lt;\/artifactId&gt;\t\t\t\t\r\n\t\t\t\t&lt;\/exclusion&gt;\r\n\t\t\t&lt;\/exclusions&gt;\r\n\t\t&lt;\/dependency&gt;\r\n\r\n<\/pre>\n<p><\/span><\/div>\n<div>Then you add in the dependencies for your other logging frameworks. \u00a0 See further\u00a0<a href=\"http:\/\/www.slf4j.org\/\">http:\/\/www.slf4j.org\/<\/a> and\u00a0<a href=\"http:\/\/search.maven.org\/#search%7Cga%7C1%7Cg%3A%22org.slf4j%22\">slf4j in search.maven.org<\/a><\/div>\n<div><strong>JAXB<\/strong><\/div>\n<div>docx4j relies very heavily on JAXB. \u00a0With Java 6 or 7, usually it&#8217;ll use the JAXB included in that (though things can be different with application servers &#8211; see the deployment forums for details).<\/div>\n<div>The point here is that there is an alternative JAXB implementation, called <strong>EclipseLink MOXy<\/strong> (see\u00a0<a href=\"http:\/\/www.eclipse.org\/eclipselink\/moxy.php\">http:\/\/www.eclipse.org\/eclipselink\/moxy.php<\/a>), which is very well supported by its developers. \u00a0You can try it with docx4j. \u00a0To do so, just include the following additional dependencies:<\/div>\n<div>\n<p>\t<dependency><br \/>\n\t\t<groupId>org.docx4j<\/groupId><br \/>\n\t\t<artifactId>docx4j-MOXy-JAXBContext<\/artifactId><br \/>\n\t\t<version>3.0.0<\/version><br \/>\n\t<\/dependency><\/p>\n<p>\t<dependency><br \/>\n\t\t<groupId>org.eclipse.persistence<\/groupId><br \/>\n\t\t<artifactId>org.eclipse.persistence.moxy<\/artifactId><br \/>\n\t\t<version>2.5.1<\/version><br \/>\n\t<\/dependency><br \/>\n\/sourcecode]\n<\/div>\n<div>Since using MOXy with docx4j is all quite new, you may run into some minor issues. \u00a0If you do, please let us know in the docx4j forums (with sufficient info for us to reproduce what you are seeing!). \u00a0Thanks.<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>blog\/2011\/10\/hello-maven-central\/ walks you through the basics of using docx4j in an Eclipse project with the help of m2eclipse. This post is about the different ways you can set up docx4j 3.0 with the help of Maven. We&#8217;ll be using the following skeleton pom.xml: &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;project xmlns=&quot;http:\/\/maven.apache.org\/POM\/4.0.0&quot; xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:schemaLocation=&quot;http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/maven-v4_0_0.xsd&quot;&gt; &lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt; &lt;groupId&gt;your.group&lt;\/groupId&gt; &lt;artifactId&gt;your.artifactp&lt;\/artifactId&gt; &lt;name&gt;nameless&lt;\/name&gt; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-253","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/comments?post=253"}],"version-history":[{"count":5,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions"}],"predecessor-version":[{"id":255,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/posts\/253\/revisions\/255"}],"wp:attachment":[{"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/media?parent=253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/categories?post=253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.docx4java.org\/blog\/wp-json\/wp\/v2\/tags?post=253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}