Showing posts with label JBOSS. Show all posts
Showing posts with label JBOSS. Show all posts

Tuesday, December 04, 2012

J2EE Web Application Deployment setup for Development in JBoss AS 7.1

Deploying a J2EE web application is very easy in JBoss AS 7.1.x server. Make your J2EE application as a war file, login to JBoss admin console, in Manage Deployments area, you can upload the war file and Enable it to make it deployed. But, is it possible to keep the deployment process like this while you are developing an application? Certainly not. This process will consume lot of time to see the development changes working.

This post will help you to setup the deployment process for development in JBoss.

Instead of deploying the application as a war file, we are going to deploy it as a exploded war directory under <JBoss Home>/standalone/deployments/. This is called exploded deployment, which helps development in greater extent. Follow the steps to get the exploded deployment working,


  • Create a directory with .war suffixed with your application name under   <JBoss Home>/standalone/deployments/ directory.
  • In <JBoss Home>/standalone/configuration/standalone.xml, add auto-deploy-exploded="true"  attribute to deployment-scanner node under deployment-scanner subsystem. 
  • You can also set scan-interval (scan-interval="5000") attribute and set your an interval to the  deployment-scanner node. For example,
            <deployment-scanner path="deployments" relative-to="jboss.server.base.dir" scan-interval="5000" auto-deploy-exploded="true" deployment-timeout="1200"/>
  • If the above are done, you have to get the J2EE application contents placed in the deployment directory we have created. It is better to link the output folders to the deployment directory, if you are using an Eclipse based IDE. JBoss will redeploy the application when it finds a change in the code. So all you have to do while development is, do a build when you want to see the code changes working.


When I was running the application successfully, I noticed that all the cookies from the application is suffixed with . undefined . For example, 

Ur1bLe3UDdWJ9xm0ZDbMfZvJ.undefined

this is a bug in JBoss 7.1x and as a workaround, you have to set instance-id attribute in jboss:domain:web subsystem in standalone.xml. For example,

<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" native="false" instance-id="myDomain">

This is not a serious issue, but include the above configuration changes as a good practice. 



Friday, November 30, 2012

Quick Setup of JBoss 7.1 with MySql Datasource

This post will help you to setup JBoss AS 7.1.x with MySql Datasource. 

As a precondition, we should have the following ready in our development environment
JDK 1.7
MySql
JBoss AS 7.x 


Run JBoss Server
Once downloaded and extracted JBoss AS 7.1, you can run the server by executing the <JBoss home>/bin/standalone batch (Windows) or shell(Linux) file, based on your OS. Make sure the server got started without any errors by checking the logs. You can also verify by visiting the url http://localhost:8080 in your browser, which shows you the JBoss home page.


Create User
We have to create users to access JBoss administration console. To add new users run add-<JBoss Home>/bin/add-user batch (Windows) or shell(Linux) file, based on your OS. This utility requires Realm, Username and Password. Releam is the name of the realm used to secure the management interfaces, by default it is 'ManagementRealm' so you can just press enter. Also enter Username and Password to complete the user creation. Now you can login using the created Username and Password, by clicking the Administration Console link from JBoss home page.


Setup Datasource
To setup MySql datasource we have to add MySql driver as a module and create the driver & datasource. Let us get into detail on how to do this. Download MySql Connector Java, jar file and place it in <JBoss Home>/modules/com/mysql/main directory. Create a xml file in the main directory named, module.xml and copy paste the following code in it,


<?xml version="1.0" encoding="UTF-8"?>

<module xmlns="urn:jboss:module:1.0" name="com.mysql">
    <resources>
        <resource-root path="mysql-connector-java-5.1.18.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
    </dependencies>
</module>


Open <JBoss Home>/standalone/configuration/standalone.xml file to add the MySql driver and create datasource. Find the datasource subsystem(
<subsystem xmlns="urn:jboss:domain:datasources:1.0">) node in the xml file, and add the following code under drivers node.


<driver name="mysql" module="com.mysql"/>


To create datasource, add a new datasource node under datasources node with your MySql database configurations in 
datasource subsystem. The following is a sample one.


<datasource jta="true" jndi-name="java:/name-of-the-data-source" pool-name="name-of-the-pool" enabled="true" use-java-context="true" use-ccm="true">

         <connection-url>jdbc:mysql://localhost:3306/db-name</connection-url>
         <driver>mysql</driver>
         <security>
             <user-name>root</user-name>
             <password>root</password>
         </security>
         <statement>
              <prepared-statement-cache-size>100</prepared-statement-cache-size>
              <share-prepared-statements>true</share-prepared-statements>
         </statement>
</datasource> 


Once you are done with the above, restart the server, login to admin console, and click Datasources to view the created datasource. You can use this datasource in your J2EE application to connect to MySql database.