Friday, February 17, 2012

JBoss AS 7.1.0.Final "Thunder" released - Java EE 6 Full Profile certified!


After just about more than a year of development on JBoss AS7, we have now released 7.1.0.Final "Thunder"! The download is available at the usual place here. This is a really big achievement for the JBoss AS7 team and we are really proud about this release.

This release contains numerous bug fixes from 7.1.0.CR1b which was released a few months back. But the biggest news about this release is that JBoss AS 7.1.0.Final is Java EE 6 Full Profile certified! I'm sure a lot of our users will be very happy about this news. AS 7.0.x was Web Profile certified but I have seen in the forums that many of you were waiting for the Full Profile certification to happen. So here's a very good reason to start using JBoss AS7, if you haven't done yet.

Apart from the Full Profile certification, AS 7.1.0.Final contains a lot of bug fixes and other JIRA issues resolved. The entire release notes can be found here.

Like in some of my previous posts on AS7 releases, in this post I'll explain atleast one new feature of this release. Many of you would know that JBoss AS7 is very different compared to the previous JBoss AS versions, on various counts. One prominent difference is that we no longer have numerous XML files in the distribution, configuring various services. Instead we just have *one* single configuration file which governs the entire server. Furthermore, unlike previous JBoss AS versions, JBoss AS7 (prior to 7.1.0.Final) did not allow *deploying* XML files to configure datasources and JMS queues. However, the community members have been repeatedly asking for this feature and JBoss AS 7.1.0.Final now allows deploying of datasources and JMS queues via application specific XML files (in addition to configuring them centrally in the domain/standalone configuration file). So let's take a quick look at how it's done in 7.1.0.Final.

Deploying datasource via -ds.xml files in JBoss AS 7.1.0.Final

The datasource file is expected to end with the -ds.xml suffix, like in previous JBoss AS releases. You can place the *-ds.xml file in the JBOSS_HOME/standalone/deployments folder or even package it in the application under the META-INF folder of the application. If it's a .war application, then the *-ds.xml is expected to be right under the WEB-INF folder of the .war.

The *-ds.xml is expected to follow the jboss-as-datasources xsd which looks like this. So you have a datasources element under which you can define multiple datasource elements. In this example, we'll try and create a MySQL datasource and deploy it as  mysql-ds.xml.

Before creating the datasource, we first have to install the database driver. AS7 allows you install the database driver either as a deployment or as JBoss Module. For more details on this, see this article. In this post, we'll deploy the driver as a JBoss Module.

Create and install the database driver

As a first step, we'll require the MySQL driver jar file. I downloaded the driver jar from the MySQL download site here. The step to create the JBoss Module for this driver involves creating a module.xml which looks like this and is named module.xml:

 <module xmlns="urn:jboss:module:1.1" name="mysql">  
   
   <resources>  
     <resource-root path="mysql-connector-java-5.1.18-bin.jar"/>  
   </resources>  
   <dependencies>  
     <module name="javax.api"/>  
     <module name="javax.transaction.api"/>  
   </dependencies>  
 </module>  
We place the mysql-connector-java-5.1.18-bin.jar and this module.xml file in JBOSS_HOME/modules/mysql/main folder (you'll have to create the mysql/main folder). That completes the JBoss Module creation for the MySQL driver. Now let's install this driver so that it gets registered in the standalone/domain configurations. In this example, we'll be using the standalone server. So let's start the server using:
 ./standalone.sh  
Once the server is up, let's open the Command Line Interface (CLI) utility which is shipped in AS7. The CLI startup script is in the JBOSS_HOME/bin folder and can be started as follows (more details about the CLI can be found here)
 ./jboss-cli.sh --connect  
Once connected successfully, we'll add the jdbc-driver using the following command:
 /subsystem=datasources/jdbc-driver=mysql-5-driver:add(driver-name=mysql-5-driver, driver-class-name=com.mysql.jdbc.Driver, driver-module-name=mysql)  
So here we are naming the driver as "mysql-5-driver" (you can name it anything). The driver-module-name points to the "mysql" JBoss Module that we created in previous step. The driver-class-name is the fully qualified classname of the MySQL driver. In this case, it's com.mysql.jdbc.Driver.

A successful execution of that command will show the output as success:
 [standalone@localhost:9999 /] /subsystem=datasources/jdbc-driver=mysql-5-driver:add(driver-name=mysql-5-driver, driver-class-name=com.mysql.jdbc.Driver, driver-module-name=mysql)  
 {"outcome" => "success"}  
   
The installation will be persisted in the configuration file which was used to start the server. In this case it's the standalone.xml and this is how it looks like after the driver has been installed:
 <subsystem xmlns="urn:jboss:domain:datasources:1.0">  
      ...  
           <drivers>  
                ...  
                <driver name="mysql-5-driver" module="mysql">  
                     <driver-class>com.mysql.jdbc.Driver</driver-class>  
                </driver>  
           </drivers>  
      </datasources>  
 </subsystem>  
We are now done with the driver installation. Now let's move on and create the mysql-ds.xml file.

Create the mysql-ds.xml file

As previously mentioned, the mysql-ds.xml should follow the jboss-as-datasources xsd. Here's how the file looks like in our case:
 <?xml version="1.0" encoding="UTF-8"?>  
 <datasources>  
   <datasource jndi-name="java:jboss/datasources/MySQLDS" enabled="true" use-java-context="true"  
         pool-name="MySQLDS">  
     <connection-url>jdbc:mysql://localhost:3306/test</connection-url>  
     <driver>mysql-5-driver</driver>  
     <security>  
       <user-name>foo</user-name>  
       <password>bar</password>  
     </security>  
   </datasource>  
 </datasources>  
Let's see what that xml file contains. The "jndi-name" is the name to which the datasource will be bound to (you can use a name of your choice. Ideally, it would be good to bind them in java:jboss/datasources/ namespace). The "enabled=true" indicates that the datasource should be enabled after being deployed. The "use-java-context" attribute is used to indicate that the JNDI name should be bound under the java: namespace. The "connection-url" is the URL to be used for connecting to the MySQL database (check MySQL documentation for more details about the connection-url). The "driver" element points to the installed JDBC driver that we created in the previous step. In our example, we named it mysql-5-driver and that's what we use here. Finally, the "security" section contains the username and password information for connecting to the database. Make sure you use the appropriate values for all these configurations.

So now let's place this mysql-ds.xml in the JBOSS_HOME/standalone/deployments folder and see JBoss AS7 hot deploy it (if the server is already running). The logs will show the following on successful deployment:
 14:05:55,829 INFO [org.jboss.as.server.deployment] (MSC service thread 1-3) JBAS015876: Starting deployment of "mysql-ds.xml"  
 14:05:55,847 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-2) JBAS010400: Bound data source [jboss/datasources/MySQLDS]  
   
So that's it! We have successfully deployed the MySQL datasource through a -ds.xml file in 7.1.0.Final!

So download this new version and start deploying your applications and start using these features. We'll be blogging more about the features in this release, in the upcoming days (after the AS7 developers get some much needed sleep :) ). So keep an eye on the jboss.org blogs. If you run into any issues with AS7, feel free to visit our user forum and ask for help.

11 comments:

Aleksandar Kostadinov said...

Can that be done without restarting AS7?

Jaikiran said...

AK, sorry I don't understand the question. What part of it do you want to do without restarting the server? The driver installation is via the command line and doesn't require server restart. Same is the case with deploying -ds.xml. It too doesn't require server restart. Does that answer your question?

Aleksandar Kostadinov said...

yep, that answers the question, wanted to be sure, very nice post!

Rang said...

Whats 7.1.1, thats what I get when I build the source code?

Jaikiran said...

Rang, 7.1.1 is the next version that will be released and will contain bug fixes, post 7.1.0.Final. The current upstream is now open for 7.1.1 development and hence you are seeing 7.1.1 version when you build from upstream source.

What exactly do you want to do? Build 7.1.0.Final from a tag or build latest upstream? Or do you just want a pre-built platform independent binary of 7.1.0.Final?

Rang said...

Thanks Jai, I was just looking to build 7.1.0 from the source.

Jaikiran said...

To build 7.1.0.Final from source, here's the tag https://github.com/jbossas/jboss-as/tree/7.1.0.Final

Unknown said...

Nice blog ,
I would like to know is there a way to configure the jms queue and jaas security settings outside of standalone.xml . I want to configure then in a separate xml file .

Unknown said...

I have this error
{
"outcome" => "failed",
"failure-description" => "JBAS010441: Failed to load module for driver [mysq
l]",
"rolled-back" => true
}
Can you help me please?

Jaikiran said...

Mouna, please create a forum discussion with the relevant details here https://community.jboss.org/community/jbossas7?view=discussions. I or someone else should then be able to help you.

Sharan said...

Thanks a lot.