12.3.  Setting Classpath in Eclipse, ANT, Maven

All development environments need a classpath with these entries:

If PDFUnit does not find the files it will give error messages like these:

In the following examples show how to configure the classpath in different environments. Additionally chapter 12.4: “Set Paths Using System Properties” describes how to use system properties to declare the location of the files pdfunit.config and license-key_pdfunit-java.lic.

Configuring Eclipse

A simple way to configure Eclipse for PDFUnit is to include the installation directory PDFUNIT_HOME and all JAR files individually in the classpath:

Another option is to move the file pdfunit.config out of PROJECT_HOME into another folder, for example src/test/resources, and put that folder into the classpath.

PDFUnit includes the file PDFUNIT_HOME/pdfunit-java-VERSION_javadoc.zip which can be registered in Eclipse to let Eclipse show the Javadoc comments.

Configuring ANT

Many options exist to configure ANT for PDFUnit. In all options the JAR files of PDFUNIT_HOME and PDFUNIT_HOME/lib/* have to be put into the classpath. Additionally the file pdfunit.config must be included in classpath.

If you have not changed the pdfunit.config, it is simple to include PDFUNIT_HOME itself in the classpath additionally to the JAR files as is shown by the following listing:

<!--
  It is important to have the directory of PDFUnit itself in the classpath,
  because the file 'pdfunit.config' must be found. 
-->
<property name="dir.build.classes"          value="build/classes" />
<property name="dir.external.tools"         value="lib-ext" />
<property name="dir.external.tools.pdfunit" value="lib-ext/pdfunit-2016.05" />

<path id="project.classpath">
  <pathelement location="${dir.external.tools.pdfunit}" />
  <pathelement location="${dir.build.classes}" />
  
  <!-- If there are problems with duplicate JARs, use more detailed filesets: -->
  <fileset dir="${dir.external.tools}">
    <include name="**/*.jar"/>
  </fileset>
</path>

The file pdfunit.config can be moved to an individual folder, for example into src/test/resources. This way is recommended if you want to change the config file. How to configure PDFUnit is described in chapter 12.5: “Using the pdfunit.config File”. Then the classpath in ANT looks like this:

<path id="project.classpath">
  <!-- 
  The file 'pdfunit.config' should not be located more than once in
  the classpath, because it hurts the DRY principle.
  -->
  <pathelement location="src/test/resources" />
  <pathelement location="${dir.external.tools.pdfunit}" />
  <pathelement location="${dir.build.classes}" />
  
  <!-- If there are problems with duplicate JARs, use more detailed fileset: -->
  <fileset dir="${dir.external.tools}">
    <include name="**/*.jar"/>
  </fileset>
</path>

Configuring Maven

The current release of PDFUnit (2016.05) is not provided in a public Maven repository. To use it with Maven despite this fact, you have to install it into a local or company-wide repository. You can do it with the following command. Change to the directory PDFUNIT_HOME\lib and run this command:

mvn install:install-file -Dfile=<PATH_TO>pdfunit-java-VERSION.jar -DpomFile=<PATH_TO>pom.xml

The next step is to copy pdfunit.config into the directory src/test/resources.

The following image shows the resulting project layout:

Directory structure for Maven

Register the PDFUnit library to your pom.xml.

<dependency>
  <groupId>com.pdfunit</groupId>
  <artifactId>pdfunit</artifactId>
  <version>2016.05</version>
  <scope>compile</scope>
</dependency>

Last Step for Licensed PDFUnit

The license file license-key_pdfunit-java.lic must also be included in the classpath. Otherwise the message box with the math calculation is shown.