June 22, 2017 Webby

Using the Maven 2.0 Plugin

Maven 2.0 has become a very popular tool for building and managing Java projects. JODConverter itself is build using Maven, and the library is available as an artifact from the central Maven repository so it can be included as a dependency in your own Maven-managed projects simply by adding the following lines to your project’s pom.xml:

    <dependency>
      <groupId>com.artofsolving</groupId>
      <artifactId>jodconverter</artifactId>
      <version>2.2.1</version>
    </dependency>

Additionally JODConverter is now also available as a Maven plugin, meaning that it can be used as part of the build process as well. A typical usage for this is writing some project documentation in OpenDocument format, and have it automatically converted to PDFs (and/or other formats) when generating the project website with mvn site.

Here is a sample pom.xml configuration that shows how convert any ODT documents in src/site/resources to PDF in the generated website when running mvn site:

  <build>
    <plugins>
      <plugin>
        <groupId>com.artofsolving</groupId>
        <artifactId>jodconverter-maven-plugin</artifactId>
        <version>2.2.1</version>
         <configuration>
           <sourceDirectory>${basedir}/src/site/resources</sourceDirectory>
           <outputDirectory>${project.reporting.outputDirectory}</outputDirectory>
           <include>**/*.odt</include>
           <outputFormat>pdf</outputFormat>
         </configuration>
         <executions>
           <execution>
             <id>convert </id>
             <phase>site</phase>
             <goals>
               <goal>convert</goal>
             </goals>
           </execution>
         </executions>
      </plugin>
    </plugins>
  </build>

Note that as usual OpenOffice.org must already be running and listening to port 8100 (or otherwise configured) for the converter to work.

The executions section tells Maven to execute the conversions as part of the mvn:site command. Alternatively, you can execute only the convert target by typing mvn jodconverter:convert.

These are all the available configuration properties:

  • sourceDirectory: required
  • outputDirectory: required
  • include: required; file pattern or list of (comma or space separated) patterns.
    Exampes: “**/*.odt” for all ODTs, “**/*.odt, **/*.ods” for all ODT or ODS in the sourceDirectory
  • outputFormat: required; single or (comma or space separated) list.
    Examples: “pdf” for PDF only, “pdf, rtf” for converting to both PDF and RTF.
  • port: optional, defaults to 8100; OpenOffice.org port number.