hawtio Maven Plugins
hawtio offers a number of Maven Plugins, so that users can bootup Maven projects and have hawtio embedded in the running JVM.
Maven Goals
hawtio offers the following Maven Goals, and each goal is further documented below:
Goal | Description |
---|---|
run | This goal runs the Maven project, by executing the configured mainClass (as a public static void main) |
spring | This goal runs the Maven project as a Spring application, by loading Spring XML configurations files from the classpath or file system. |
spring-boot | This goal runs the Maven project as a Spring Boot application, by executing the configured Spring Boot mainClass. |
camel | This goal is an extension to the Apache Camel Maven Plugins, allowing to run the Camel Maven project and have hawtio embedded. This allows users to gain visibility into the running JVM, and see what happens, such as live visualization of the Camel routes, and being able to debug and profile routes, and much more, offered by the Camel plugin. |
camel-blueprint | The same as the camel goal but needed when using OSGi Blueprint Camel applications. |
camel-cdi | The same as the camel goal but needed when using CDI Camel applications. |
test | This goal run the unit tests of the Maven project. Can be used together with the JUnit plugin to run unit tests from within hawtio console as well. |
Common Maven Goal configuration
All of the hawtio Maven Plugins provides the following common options:
Option | Default | Description |
---|---|---|
logClasspath | false | Whether to log the classpath. |
logDependencies | false | Whether to log resolved Maven dependencies. |
offline | false | Whether to run hawtio in offline mode. Some of the hawtio plugins requires online connection to the internet. |
run Maven Goal configuration
Currently all of the hawtio Maven Plugins provides the following common options:
Option | Default | Description |
---|---|---|
context | hawtio | The context-path to use for the embedded hawtio web console. |
port | 8080 | The port number to use for the embedded hawtio web console. Notice the spring-boot goal uses port 9191 as default. |
mainClass | The fully qualified name of the main class to executed to bootstrap the Maven project. This option is required, and must be a public static void main Java class. | |
openWebConsole | true | Wheter to automatic open the hawtio web console after 3 number of seconds |
openWebConsoleDelay | 3 | Number of seconds to wait before opening the web console |
arguments | Optional arguments to pass to the main class. | |
systemProperties | Optional system properties to set on the JVM. |
spring Maven Goal configuration
The spring goal extends the run goal and provides the following additional options:
Option | Default | Description |
---|---|---|
applicationContextUri | META-INF/spring/*.xml | Location on class-path to look for Spring XML files. Mulutple paths can be seperated with semi colon. Only either one of applicationContextUri or fileApplicationContextUri can be in use. |
fileApplicationContextUri | Location on file system to look for Spring XML files. Mulutple paths can be seperated with semi colon. Only either one of applicationContextUri or fileApplicationContextUri can be in use. |
spring-boot Maven Goal configuration
The spring-boot goal has no additional options.
camel Maven Goal configuration
The camel goal extends the run goal and provides the following additional options:
Option | Default | Description |
---|---|---|
applicationContextUri | META-INF/spring/*.xml | Location on class-path to look for Spring XML files. Mulutple paths can be seperated with semi colon. Only either one of applicationContextUri or fileApplicationContextUri can be in use. |
fileApplicationContextUri | Location on file system to look for Spring XML files. Mulutple paths can be seperated with semi colon. Only either one of applicationContextUri or fileApplicationContextUri can be in use. |
By default the camel plugin will assume the application is a Camel spring application and use the applicationContextUri or fileApplicationContextUri to use as Spring XML files. By configurign a custom mainClass, then the Camel application is using the custom mainClass to bootstrap the Camel application, and neither applicationContextUri, nor fileApplicationContextUri are in use.
camel-blueprint Maven Goal configuration
The camel goal extends the run goal and provides the following additional options:
Option | Default | Description |
---|---|---|
applicationContext | OSGI-INF/blueprint/*.xml | Location on class-path to look for Blueprint XML files. Mulutple paths can be seperated with semi colon. Only either one of applicationContext or fileApplicationContext can be in use. |
fileApplicationContext | Location on file-system to look for Blueprint XML files. Mulutple paths can be seperated with semi colon. Only either one of applicationContext or fileApplicationContext can be in use. | |
configAdminPid | To use a custom config admin persistence id. The configAdminFileName must be configured as well. | |
configAdminFileName | Location of the configuration admin configuration file |
camel-cdi Maven Goal configuration
The camel-cdi goal has no additional options.
test Maven Goal configuration
The test hawtio Maven Plugins provides the following common options:
Option | Default | Description |
---|---|---|
className | Optional to select a specific unit test class to start testing (must specific class name as fully qualified classname) | |
testName | Optional to select a specific test method(s) to filter and use for testing. You can use * as wildcard to match multiple test methods. |
If no className has been specified then hawtio is started up included the projects test classpath, and the junit plugin can be used to select tests to run from within hawtio console itself.
If a className has been specified then unit testing of the selected class happens when hawtio has been started, but the unit test will not tear down until the user press enter in the shell. This is on purpose allowing using hawtio to inspect the state of the JVM during and after testing. For example to look at the Camel plugin to see route diagrams and profiles with metrics from the completed unit tests.
Pressing enter in the shell runs the tear down of the unit tests, which for example could unregister Camel from JMX and therefore remove the CamelContext used during testing. When using the junit plugin to run unit tests, then these tests will tear down immediately when they complete, and therefore remove any CamelContexts during testing. This may change in the future, allows to keep the CamelContexts alive after testing, giving end users time to inspect the data; and then tear down by pressing a button.
Configuring hawtio Maven Plugin in pom.xml
In the Maven pom.xml file, the hawtio plugin is configured by adding the following in the <build><plugin>section:
<plugin>
<groupId>io.hawt</groupId>
<artifactId>hawtio-maven-plugin</artifactId>
<version>1.5.11</version>
<configuration>
<!-- configuration options goes here -->
</configuration>
</plugin>
In the <configuration> section we can configure the plugin with any of the options mentioned before. For example to log the classpath:
<configuration>
<logClasspath>true</logClasspath>
</configuration>
And to change the port number from 8282 to 8090 do:
<configuration>
<logClasspath>true</logClasspath>
<port>8090</port>
</configuration>
And to set a number of system properties to the JVM, such as the JVM http proxy settings is simply done within the nested <systemProperties> tag:
<configuration>
<logClasspath>true</logClasspath>
<port>8090</port>
<systemProperties>
<http.proxyHost>myproxyserver.org</http.proxyHost>
<http.proxyPort>8081<http.proxyPort>
</systemProperties>
</configuration>
Camel Examples
The Apache Camel distributons includes a number of examples, which you can try out using Maven plugins.
For example to try the Camel console from a shell type:
cd examples
cd camel-example-console
mvn compile
mvn camel:run
To run the same example with hawtio embedded as a web console, you simply do
cd examples
cd camel-example-console
mvn compile
mvn io.hawt:hawtio-maven-plugin:1.5.11:camel
Where 1.5.11 is the hawtio version to use.
Adding hawtio plugin to the Apache Camel examples
In any Maven pom.xml file you can include the hawtio Maven plugin. For example to include the hawtio plugin in the Camel console example, you edit the pom.xml file in examples/camel-example-console directory.
In the <build><plugin>section add the following xml code:
<plugin>
<groupId>io.hawt</groupId>
<artifactId>hawtio-maven-plugin</artifactId>
<version>1.5.11</version>
</plugin>
And you can run the console example simply by typing
mvn hawtio:camel
And the example is started together with the embedded hawtio web console, such as the screenshot below illustrates: