Since Artemis 1.1.0 Artemis provides the possibility of using Maven Plugins to manage the life cycle of servers.

1. When to use it

These Maven plugins were initially created to manage server instances across our examples. They can create a server, start, and do any CLI operation over servers.

You could for example use these maven plugins on your testsuite or deployment automation.

2. Goals

There are three goals that you can use

create

This will create a server accordingly to your arguments. You can do some extra tricks here such as installing extra libraries for external modules.

cli

This will perform any CLI operation. This is basically a maven expression of the CLI classes

runClient

This is a simple wrapper around classes implementing a static main call. Notice that this won’t spawn a new VM or new Thread.

3. Declaration

On your pom, use the plugins section:

  1. <build>
  2. <plugins>
  3. <plugin>
  4. <groupId>org.apache.activemq</groupId>
  5. <artifactId>artemis-maven-plugin</artifactId>
  6. </plugin>
  7. </plugins>
  8. </build>

4. create goal

I won’t detail every operation of the create plugin here, but I will try to describe the main parameters:

NameDescription

configuration

A place that will hold any file to replace on the configuration. For instance if you are providing your own broker.xml. Default is “${basedir}/target/classes/activemq/server0”

home

The location where you downloaded and installed artemis. Default is “${activemq.basedir}”

alternateHome

This is used case you have two possible locations for your home (e.g. one under compile and one under production

instance

Where the server is going to be installed. Default is “${basedir}/target/server0”

liblist[]

A list of libraries to be installed under ./lib. ex: “org.jgroups:jgroups:3.6.0.Final”

Example:

  1. <execution>
  2. <id>create</id>
  3. <goals>
  4. <goal>create</goal>
  5. </goals>
  6. <configuration>
  7. <ignore>${noServer}</ignore>
  8. </configuration>
  9. </execution>

5. cli goal

Some properties for the CLI

NameDescription

configuration

A place that will hold any file to replace on the configuration. For instance if you are providing your own broker.xml. Default is “${basedir}/target/classes/activemq/server0”

home

The location where you downloaded and installed artemis. Default is “${activemq.basedir}”

alternateHome

This is used case you have two possible locations for your home (e.g. one under compile and one under production

instance

Where the server is going to be installed. Default is “${basedir}/target/server0”

Similarly to the create plugin, the artemis exampels are using the cli plugin. Look at them for concrete examples.

Example:

  1. <execution>
  2. <id>start</id>
  3. <goals>
  4. <goal>cli</goal>
  5. </goals>
  6. <configuration>
  7. <spawn>true</spawn>
  8. <ignore>${noServer}</ignore>
  9. <testURI>tcp://localhost:61616</testURI>
  10. <args>
  11. <param>run</param>
  12. </args>
  13. </configuration>
  14. </execution>

5.1. runClient goal

This is a simple solution for running classes implementing the main method.

NameDescription

clientClass

A class implement a static void main(String arg[])

args

A string array of arguments passed to the method

Example:

  1. <execution>
  2. <id>runClient</id>
  3. <goals>
  4. <goal>runClient</goal>
  5. </goals>
  6. <configuration>
  7. <clientClass>org.apache.activemq.artemis.jms.example.QueueExample</clientClass>
  8. </configuration>
  9. </execution>

5.2. Complete example

The following example is a copy of the /examples/features/standard/queue example. You may refer to it directly under the examples directory tree.

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  3. <modelVersion>4.0.0</modelVersion>
  4. <parent>
  5. <groupId>org.apache.activemq.examples.broker</groupId>
  6. <artifactId>jms-examples</artifactId>
  7. <version>1.1.0</version>
  8. </parent>
  9. <artifactId>queue</artifactId>
  10. <packaging>jar</packaging>
  11. <name>ActiveMQ Artemis JMS Queue Example</name>
  12. <properties>
  13. <activemq.basedir>${project.basedir}/../../../..</activemq.basedir>
  14. </properties>
  15. <dependencies>
  16. <dependency>
  17. <groupId>org.apache.activemq</groupId>
  18. <artifactId>artemis-jms-client</artifactId>
  19. <version>${project.version}</version>
  20. </dependency>
  21. </dependencies>
  22. <build>
  23. <plugins>
  24. <plugin>
  25. <groupId>org.apache.activemq</groupId>
  26. <artifactId>artemis-maven-plugin</artifactId>
  27. <executions>
  28. <execution>
  29. <id>create</id>
  30. <goals>
  31. <goal>create</goal>
  32. </goals>
  33. <configuration>
  34. <ignore>${noServer}</ignore>
  35. </configuration>
  36. </execution>
  37. <execution>
  38. <id>start</id>
  39. <goals>
  40. <goal>cli</goal>
  41. </goals>
  42. <configuration>
  43. <spawn>true</spawn>
  44. <ignore>${noServer}</ignore>
  45. <testURI>tcp://localhost:61616</testURI>
  46. <args>
  47. <param>run</param>
  48. </args>
  49. </configuration>
  50. </execution>
  51. <execution>
  52. <id>runClient</id>
  53. <goals>
  54. <goal>runClient</goal>
  55. </goals>
  56. <configuration>
  57. <clientClass>org.apache.activemq.artemis.jms.example.QueueExample</clientClass>
  58. </configuration>
  59. </execution>
  60. <execution>
  61. <id>stop</id>
  62. <goals>
  63. <goal>stop</goal>
  64. </goals>
  65. <configuration>
  66. <ignore>${noServer}</ignore>
  67. </configuration>
  68. </execution>
  69. </executions>
  70. <dependencies>
  71. <dependency>
  72. <groupId>org.apache.activemq.examples.broker</groupId>
  73. <artifactId>queue</artifactId>
  74. <version>${project.version}</version>
  75. </dependency>
  76. </dependencies>
  77. </plugin>
  78. </plugins>
  79. </build>
  80. </project>