Help

With the 7.0.1 release of AS7 comes a new release of the JBoss AS7 Maven Plugin. In addition to allowing you to deploy your apps to AS7, the plugin now has the ability to automatically add datasources to a running AS7 instance.

Deploying a datasource is a two stage process, first we have to deploy the driver, then we setup a datasource through the AS7 management api. The example below walks you through the process of deploying a postgresql datasource, but for the impatient among you a complete example can be found here.

Deploying a database driver

To deploy a database driver we first have to list our driver in the <dependencies> section of pom.xml:

<dependencies>
  <dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>8.4-702.jdbc4</version>
  </dependency>
</dependencies>

We then have to setup the JBoss AS7 Maven plugin to deploy the datasource to the app server:

<plugin>
    <groupId>org.jboss.as.plugins</groupId>
    <artifactId>jboss-as-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>deploy-driver</id>
            <phase>package</phase>
            <configuration>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <name>postgresql.jar</name>
            </configuration>
            <goals>
                <goal>deploy-artifact</goal>
            </goals>
        </execution>
    </executions>
</plugin>

Running mvn package will now connect to a running AS7 instance on localhost and deploy the driver as a deployment named postgresql.jar.

Note that this capability it not limited to just deploying database drivers, using the deploy-artifact goal it is possible to deploy any maven artifact to the app server.

Creating the DataSource

Now that we have our driver deployed, we need to create the DataSource. To do this, we will need to update our pom again so it looks like this:

<plugin>
    <groupId>org.jboss.as.plugins</groupId>
    <artifactId>jboss-as-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>deploy-driver</id>
            <phase>package</phase>
            <configuration>
                <groupId>postgresql</groupId>
                <artifactId>postgresql</artifactId>
                <name>postgresql.jar</name>
            </configuration>
            <goals>
                <goal>deploy-artifact</goal>
            </goals>
        </execution>
        <execution>
            <id>add-datasource</id>
            <phase>install</phase>
            <configuration>
                <address>subsystem=datasources,data-source=myDatasource</address>
                <properties>
                    <connection-url>jdbc:postgresql://localhost/myDatabase</connection-url>
                    <jndi-name>myDatasource</jndi-name>
                    <enabled>true</enabled>
                    <pool-name>myPool</pool-name>
                    <user-name>dmusername</user-name>
                    <password>secret</password>
                    <driver-name>postgresql.jar</driver-name>
                </properties>
            </configuration>
            <goals>
                <goal>add-resource</goal>
            </goals>
        </execution>
    </executions>
</plugin>

With this configuration running mvn install should deploy a Postgresql datasource to AS7.

For some more examples, including XA DataSource and MySQL examples, please see my example pom.xml at https://github.com/stuartwdouglas/quickstart/blob/master/datasource/pom.xml.

How it works

You may have noticed about that the name of the maven goal is add-resource, rather than add-datasource. This is because the plugin is not limited to just adding datasources, but can also be used to add other resources to AS7. Internally the plugin uses the AS7 management API, and the <address> and <properties> elements correspond exactly to the management API / command line equivalents. This means that we can add other resources as well, e.g. JMS Queues.

The first thing we need to do is figure out the syntax we need to use to add a JMS Queue. To do this we are going to use the command line client. Fire up an instance of AS7, and then in another terminal window run jboss-admin.sh in the bin directory. You should see the following:

You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
[disconnected /]

Type connect and you should connect to the running AS7 instance. Now we need to figure out the syntax to add a JMS Queue. To do this we run the following command:

[standalone@localhost:9999 /] /subsystem=messaging/jms-queue=*:read-operation-description(name="add")

This should give us the following result:

{
    "outcome" => "success",
    "result" => {
        "operation-name" => "add",
        "description" => "Add a queue.",
        "request-properties" => {
            "entries" => {
                "type" => LIST,
                "description" => "The jndi names the queue will be bound to.",
                "required" => true,
                "nillable" => false
            },
            "selector" => {
                "type" => STRING,
                "description" => "The queue selector.",
                "required" => false,
                "nillable" => true
            },
            "durable" => {
                "type" => BOOLEAN,
                "description" => "Whether the queue is durable or not.",
                "required" => false,
                "nillable" => true
            }
        },
        "reply-properties" => {}
    }
}

This output means that the operation has three parameters, entries, selector and durable, Of type List, String, and Boolean respectively. Using this information we can add queue on the command line as follows:

[standalone@localhost:9999 /] /subsystem=messaging/jms-queue=cmdLineQueue:add(entries=["java:jboss/cmdLineQueue"], durable=true)
{"outcome" => "success"}

Now lets re-create this from the maven plugin:

<plugin>
    <groupId>org.jboss.as.plugins</groupId>
    <artifactId>jboss-as-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>add-queue</id>
            <phase>install</phase>
            <configuration>
                <address>subsystem=messaging,jms-queue=myQueue</address>
                <properties>
                    <entries>!!["java:jboss/myQueue", "java:jboss/anotherJndiBinding"]</entries>
                    <durable>true</durable>
                </properties>
            </configuration>
            <goals>
                <goal>add-resource</goal>
            </goals>
        </execution>
    </executions>
</plugin>

The most interesting part of the above configuration is the <entries> element. Because the parameter is of a non-primitive type (in this case LIST), it must be specified as a DMR String. The !! escape as the start of the test tells the plugin to interpret it as such.

6 comments:
 
19. Aug 2011, 17:21 CET | Link
With the 7.0.1 release of AS7 comes a new release of the JBoss AS7 Maven Plugin. In addition to allowing you to deploy your apps to AS7, the plugin now has the ability to automatically add datasources to a running AS7 instance.

Hi stuart, my eyes got point on this: So this is mean that we could doing something like this or this but still in managed environment? Or I just missing something?

Thanks.

ReplyQuote
 
27. Dec 2011, 12:01 CET | Link
Marx

Link to pom.xml is invalid (404)

 
18. Sep 2014, 14:05 CET | Link

À l'heure actuelle, la CBI est connu comme l'expression la plus extrême dans l'horlogerie complexes, y compris Leonardo da Vinci (prise de rendez-droite, mais aussi les droits du cycle de la lune, jusqu'à 2499), ainsi que des complications majeures (17 propriétés physiques diverses) fabricants. Ils sont fondamentalement la capacité physique, replique montres qui est généralement au-delà des compétences de la montre tout simplement par des puces.

 
23. Oct 2014, 10:27 CET | Link
belpegor

Brilliant! I knew that a post like this would inspire millions of people across the world. Keep it up!

buy real soundcloud followers
 
18. Nov 2014, 17:53 CET | Link
Professinal writer | info(AT)buy-an-essays.com

When it comes to my college assignments, I prefer to confiding them only to the trustworthy companies. I tested several online writing services and finally picked many essays for sale here http://buy-an-essays.com/. I like the wide choice of subjects and their ability to tackle any type of assignments, even those not specified in the order form.

Post Comment