Fork me on GitHub


This zookeeper-maven-plugin enables integration testing for applications utilizing ZooKeeper servers. It will enable you to start a ZooKeeper server prior to running integration tests, and then enable you to shut it down gracefully. This plugin was inspired by the jetty-maven-plugin and behaves similarly, using a shutdownString and shutdownPort to shut down a specific instance during different phases of a Maven build lifecycle.

Configuration options are available for many of ZooKeeper’s own configuration options. It uses the ${}/zmp to store its running state, including the ZooKeeper dataDir. Multiple concurrent executions are possible, but must each must specify a unique clientPort and shutdownPort option.

Getting Started

To add this plugin to your project, configure the plugin similarly to:

          <!-- This is a unique string to kill the service when finished -->
          <!-- This is the port the plugin listens on for the shutdownString -->
          <!-- Configure the ZooKeeper port; defaults to listening on -->
            <!-- In this example, only one ZooKeeper service is started and the
            two goals share the same configuration, so the stop goal sends the
            same shutdown message that the start goal is listening for -->
              <goal>start</goal><!-- runs at pre-integration-test phase -->
              <goal>stop</goal><!-- runs at post-integration-test phase -->
            <!-- configure failsafe to execute some ITs which use ZooKeeper -->

and build your project, similarly to (it runs at the verify phase by default):

mvn verify

Retaining ZooKeeper’s Data/State

By default, zookeeper-maven-plugin will create a zmp directory under your project’s ${}. This directory is typically cleared and its children recreated with each new build. You can change the zmp directory providing the following configuration: <zmpDir>/path/to/different/zmp</zmpDir>

Now, future builds will create use that location, creating it if it doesn’t exist.

You can take it a step further and add the following to keep data between builds.


Both configurations must be present if you wish to keep data between builds. The boolean ensures the plugin itself doesn’t delete the directory, and using a different directory than the default ensures it is safe from mvn clean (assuming the directory you’ve chosen is outside your ${} and you don’t have any special clean tasks configured).