Automated JDBC-Driver and Datasource deployment with Wildfly 8.x

My goal is to configure an enterprise application so that it runs on wildfly out of the box:

  • No need to upload and/or deploy the jdbc driver
  • No need to create the datasource for the application manually
  • The deployment procedure shouldn’t be more complicated than necessary.
    This is true for daily usage – the setup is different hence this document 🙂
  • Externalize configuration details of the db configuration from the build to gain more flexibility

UPDATED:

For eager starters: There’s working example (with mysql5) on BitBucket

Assumptions:

  • We have a maven based build process
  • we want to connect to an oracle db. According to my experience it works with mysql5 and mongo db, too.
  • For now we assume Wildfly is installed locally.
  • A Property by the name “wildfly-home” existst and points to where wildfly is installed locally. If you followed my description for mac this is most propably:
    /usr/local/Cellar/wildfly-as/8.0.0.Final/libexec

Steps to take:

  1. Declare the db driver a maven dependency.
  2. Include maven wildfly plugin in the build process
  3. Add an execution step for deploying the jdbc driver
  4. Add another step to deploy the datasource
  5. Add the execution step to deploy the application

ad 1) Add db driver to dependency list

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>${mysql.driver.version}</version>
</dependency>

ad 2) add the wildfly maven plugin to the build configuration

<build>
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${maven.wildfly.plugin.version}</version>
<configuration>
<jboss-home>${wildfly-home}</jboss-home>
</configuration>
...

ad 3) Configure deployment of jdbc-jar

...

<execution>
<id>deploy_jdbc_driver</id>
<phase>package</phase>
<goals>
<goal>deploy-artifact</goal>
</goals>
<configuration>
<groupId>${mysql.groupId}</groupId>
<artifactId>${mysql.artifactId}</artifactId>
<name>${mysql.artifactId}-${mysql.driver.version}.jar</name>
</configuration>
</execution>
...

ad 4) add datasource deployment step

<execution>
<id>add_datasource</id>
<phase>package</phase>
<goals>
<goal>add-resource</goal>
</goals>
<configuration>
<address>subsystem=datasources,data-source=myDS</address>
<resources>
<resource>
<properties>
<connection-url>${db.jdbc.url}</connection-url>
<jndi-name>java:jboss/jdbc/tanken</jndi-name>
<enabled>true</enabled>
<enable>true</enable>
<user-name>${mysql.username}</user-name>
<password>${mysql.password}</password>
<driver-name>${mysql.driver.name}</driver-name>
<use-ccm>false</use-ccm>
</properties>
</resource>
</resources>
</configuration>
</execution>

ad 4) add step to deploy the application

<!– deploy the application –>
<execution>
<id>deploy_application</id>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>


Since maven wildfly plugin integrates nicely with mavens lifecycle you can install everything with one:

mvn install

Enjoy!

 

This article is based on the information provided by jboss here.

Advertisements

About javavolker71

when i do not write posts on this blog, don't work on or try to break my code i'm spending a reasonable amount of time
This entry was posted in IT, Java, JEE7, maven, Uncategorized and tagged , , , , , . Bookmark the permalink.

11 Responses to Automated JDBC-Driver and Datasource deployment with Wildfly 8.x

  1. Samuel says:

    Did you have an example with a mongoDB datasource ? I can’t do it 😦 I have the same trouble than : https://issues.jboss.org/browse/WFLY-3333 :
    {“JBAS014771: Services with missing/unavailable dependencies” => [
    “jboss.driver-demander.java:jboss/myDatasource is missing [jboss.jdbc-driver.mongo-java-driver-2_10_1_jar]”,
    “jboss.data-source.java:jboss/myDatasource is missing [jboss.jdbc-driver.mongo-java-driver-2_10_1_jar]”
    ]}}}
    Any idea ?
    thx 😉

    Like

  2. Johnk225 says:

    Hello.This post was extremely motivating, especially because I was browsing for thoughts on this subject last Thursday. aeekdecceeag

    Like

  3. Johng156 says:

    You completed a number of fine points there. I did a search on the theme and found the majority of folks will agree with your blog. deedbcfeeeed

    Like

  4. Carlo(s) says:

    Hi! I’ve a problem on deploy-artifact stage! I recive this error message: Failed to execute goal org.wildfly.plugins:wildfly-maven-plugin:1.0.2.Final:deploy-artifact (default-cli) on project Zeus: deploy-artifact must specify the artifactId -> [Help 1]
    Can you help me with this?

    Like

    • javavolker71 says:

      Hey Carlo(s),

      hmm, the artifact your going to deploy has to be declared as a project dependency. I would recommend specifying group- and artifactId as properties so you eliminate typos.
      Please refer to the (updated) linked bitbucket project. It contains a complete project for deploying a mysql driver and a datasource.
      If you have further problems or questions we get them sorted out.
      Sorry for the delay – i’ve been on vacation and started a new job.

      Happy coding,
      volker

      Like

  5. Mastouri says:

    Thanks for the nice article. Unfortunately i can not access the BitBucket repository. Can you give me access? My BitBucket account is amine-mastouri
    Kind regards
    Amine

    Like

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s