Maven Exec Plugin vs Maven AntRun Plugin for running command-line tool

Maven Exec Plugin supports the following two goals:

  1. exec: to execute external programs (including Java) in a separate process
  2. java: to execute Java programs in the same JVM

Maven AntRun Plugin supports only one goal:

  1. run: to execute the Ant target specified

If you have a requirement to run a command-line tool, e.g. cURL, in an synchronous (blocking) way, you can use the Maven Exec Plugin (exec goal). However, in case you need to run it in an asynchronous (non-blocking) fashion, you can use the Ant exec task (with ‘spawn’ option set as true) with Maven AntRun Plugin. You might want to consider something like this before executing the integration tests which could be dependent on the database being in a clean state. Here is an example:

  • Using Maven Exec Plugin
      <id>drop DB => db_name</id>
  • Using Maven AntRun Plugin
      <id>drop DB => db_name</id>
          <exec executable="curl">
            <arg value="-s" />
            <arg value="-S" />
            <arg value="-X" />
            <arg value="DELETE" />
            <arg value="http://${db.server}:${db.port}/db_name" />
            <spawn value="true">

3 responses to “Maven Exec Plugin vs Maven AntRun Plugin for running command-line tool

  1. Pingback: pandroid » PD022 – Maven

  2. Walter January 20, 2015 at 21:27

    Did you mix up your conclusions?
    When I use exec-maven-plugin with


    the second executable is called 10 seconds after the first one.
    I would conclude that Exec is blocking and Antrun scripts can be called non-blocking using the spawn option.

    • Sanchit Bahal January 21, 2015 at 00:06

      Thanks for pointing it out! I have corrected the blog post.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: