By adding the executions element in your plugin configuration, you will be able to perform some advanced activities.

For example, supposing that you want to issue your deployment automatically when you execute the maven install phase:


mvn install

Then, you need to bind the install phase to the deploy goal of your plugin. This can be done with a little add-on to your configuration::


<build>
      <plugins>
         <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>7.3.Final</version>

            <executions>
               <execution>
                  <phase>install</phase>
                  <goals>
                     <goal>deploy</goal>
                  </goals>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

Quite interestingly, you can also add resources to your application server by using the deploy-artifact and add-resource goal. Here's for example how to deploy a MySQL JDBC Driver and install a Datasource using this driver.


<build>
      <plugins>
         <plugin>
            <groupId>org.jboss.as.plugins</groupId>
            <artifactId>jboss-as-maven-plugin</artifactId>
            <version>7.3.Final</version>
            <executions>

               <execution>
                  <phase>install</phase>
                  <goals>
                     <goal>deploy</goal>
                  </goals>
               </execution>
              
               <execution>
                  <id>deploy-mysql</id>
                  <phase>package</phase>
                  <goals>
                     <goal>deploy-artifact</goal>
                  </goals>
                  <configuration>
                     <groupId>mysql</groupId>
                     <artifactId>mysql-connector-java</artifactId>
                     <name>mysql-connector-java-5.1.18-bin.jar</name>
                  </configuration>
               </execution>

               <execution>
                  <id>add-datasource</id>
                  <phase>package</phase>
                  <goals>
                     <goal>add-resource</goal>
                  </goals>
                  <configuration>
                     <address>subsystem=datasources,data-source=java:jboss/datasources/MySqlDS</address>
                     <resource>
                        <enable-resource>true</enable-resource>
                        <properties>
                           <jndi-name>java:jboss/datasources/MySqlDS</jndi-name>
                           <enabled>true</enabled>
                           <connection-url>jdbc:mysql://localhost:3306/mysqlDB</connection-url>
                           <driver-class>com.mysql.jdbc.Driver</driver-class>
                           <driver-name>mysql-connector-java-5.1.18-bin.jar</driver-name>
                           <security.user-name>root</security.user-name>
                           <security.password />
                           <pool-name>mypool</pool-name>
                        </properties>
                     </resource>
                  </configuration>
               </execution>
            </executions>
         </plugin>
      </plugins>
   </build>

As you can see, the plugin contains two additional executions: a deploy-mysql execution which will deloy the MySQL JDBC Driver to the application server, and an add-datasource execution which will configure a datasource using this driver.

In order to run this example, don't forget to add a dependency to MySQL JDBC driver in your pom.xml:


<dependency>
   <groupId>mysql</groupId>
   <artifactId>mysql-connector-java</artifactId>
   <version>5.1.18</version>
</dependency>

The Maven plugin can be used to create JMS resources such as a JMS queue:


<execution>
   <id>add-queue</id>
   <phase>install</phase>
   <configuration>
      <resource>
         <address>subsystem=messaging,hornetq-server=default,jms-queue=queue1</address>
         <properties>
            <durable>true</durable>
            <entries>!!["java:jboss/queue1", "java:jboss/queue1Alias"]</entries>
         </properties>
      </resource>
   </configuration>
   <goals>
      <goal>add-resource</goal>
   </goals>
</execution>

Finally, you can add to your configuration stanza also generic CLI commands such as the following example:

<configuration>
   <hostname>localhost</hostname>
   <port>9999</port>
   <execute-commands>
      <batch>true</batch>
      <commands>
         <command>/system-property=foo:add(value=bar)</command>
      </commands>
   </execute-commands>
</configuration>
0
0
0
s2sdefault

Related articles available on mastertheboss.com

JBoss Maven example: building a Java EE 6 application

In this tutorial we will show how to create a basic Java EE 6 app

Eclipse and Maven tutorial

In this tutorial we will show how you can create a Maven project

Maven and JBoss a concrete example: Infinispan

If you have completed the basic Maven and Eclipse tutorial we wil

Maven and JBoss: how to use BOMs to keep releases in sync

When using Maven for creating and building your projects you have

Maven for Eclipse Users Tutorials

In this article we will try to provide a kickstart guide for Mave

Maven Multi module tutorial

In this tutorial we will show how to use Maven multi-module proje