JBoss on Microsoft Azure Cloud Services PaaS

For some time, the Microsoft Azure platform has been giving support to other languages ​​such as Java, Python or PHP. An easy way to work with them is through the Microsoft Azure Web sites service which with a simple click adds support for each of them:

Microsoft Azure Web sites language support

In the case of Java, the options that we provide as web server are Tomcat and Jetty:

Web sites Java support

What if we want to work with JBoss?

In this post I’ll show how you can install JBoss on Cloud Services through the Eclipse IDE. We upload the Java application and also the web server for our site.

Installation

Starting from scratch, these are the requirements for this scenario:

  • Install Azure SDK 2.3+.
  • At the time of writing this post, the latest version of JBOSS supported by the Eclipse plugin is JBoss AS 7, so it is necessary to use Java Development Kit 7 to work properly.
  • Add to the PATH the location of the Java runtime installation:Path variable Java path
  • Eclipse IDE for Java EE Developers , Indigo or higher (at the time of this post the version used was Kepler).
  • Once we’ve downloaded Eclipse, install the plugin that gives us options within the IDE for Azure: Help > Install New Software… > Work with http://dl.msopentech.com/eclipse > Disable Contact all update sites during install to find required software. Move into the Wizard, accept the license and restart Eclipse when prompted..

Configure JBOSS on premise

Before uploading to the cloud, you must verify that the server and your application work properly on premise. The first thing we do is create a JBoss web server from Eclipse.
To do this, we go to the Servers tab and we click on the link No servers are available. Click on this link to create a new server… or right click and select New > Server.

Servers tab new Server

If you look at the list of JBOSS, the latest version is 5.0, so we click on Download additional server adapters in order to download JBossAS Tools.

JBossAS Tools

Once back to access the list of available servers, we see that the list has grown and we can select JBoss AS 7.1:

JBoss AS 7.1

Next step is you need to download the JBoss server, and we can do it directly from the wizard by clicking on Download runtime and install…

JBoss Download and install runtime...

Within the select list JBoss AS 7.1.1 (Brontes), move into the wizard and select the installation folder (make sure you have permissions on the location you choose).

Download runtime Install folder

From this moment begins the download and decompression of JBoss. The last steps for configuring JBoss are:

  1. Change the value of Home Directory location of our JBoss installation.
  2. Ensuring that the JDK selected for the server is version 7, because otherwise it will not work correctly.

Home Directory and JRE

Move on the defaults and ended up with the wizard. In the Servers tab we find that we have created two servers instead of one. No need to maintain the two, so in my case I remove one of them and I keep JBoss 7.1 Runtime Server.

Sample Project

To check both, locally and on Azure, that the server is running, we create a Dynamic Web Project ( File > New > Dynamic Web Project) with the following settings:

New Dynamic Web Project

Mantain the values by default.

In WebContent create a new JSP file called index.jsp, to take it as the default startup document.

New JSP File

The contents of the file is as follows, in order to execute some code in Java and also know the worker role instance that is serving the request:

<%@page import="java.net.InetAddress"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>JBoss on Microsoft Azure PaaS</title>
</head>
<body>
	<article>
		This is <%= InetAddress.getLocalHost().getHostName() %> instance.
	</article>
</body>
</html>

Creating the Azure project

Before uploading to the platform, you must create an Azure project associate with the configuration of our service. To do this right click on the project you just created and select Azure > Azure Package for …

Package for Azure

We choose the name of the project (Azure Project) and make sure that the JDK tab has the following configuration:

New Azure Deployment Project JDK

In the Server tab must select the location of the JBoss server we created earlier:

Azure Deployment Project Server Tab

In the Applications tab we should see a war file of the web project.

There is a final section, which contains a number of optional features:

Azure Deployment Project optional features

For this post we don’t select any of them.

Emulation on premise

Once we created the Azure project, we can launch the local emulation, checking that everything works as expected:

Run in Azure Emulator

This process may take a few minutes because it performs full emulation of this scenario (create a worker role, download within the same web server, mount it, and so on).

The result should look like this:

On the side of the worker role we can see a message that puts java.exe is running…:

Worker role java is running

To view the site which is displayed on the emulator, just go to the browser and type: http://127.0.0.1:8080/MyJavaHelloWorld:

Testing JBoss and Java locally

Also if we access the site root, we can see that this is the version of JBoss selected (for security reasons we must eliminate this type of information;))

Your JBoss Application Server 7 is running on Microsoft Azure Emulator

Publish our project to a Cloud Service

Right click on the Azure project and select Azure > Deploy to Azure Cloud, which will open a wizard where we import our subscription settings through the button Import from file … PUBLISH-SETTINGS. Through it we are allowed to select the configuration file on your hard drive and there is also a button that opens a browser window and download the Azure account configuration.

Publish Wizar Import from Publish-settings file

Once the configuration is imported, simply select the Microsoft Azure Storage account we want to use and specify the name of Cloud Service where we want to deploy the solution:

Publish Wizard Subscription options

This process can take several minutes.

Once finished, you can click directly on the link Published in Azure Activity Log that will open the deployed site:

Azure Activity Log

JBoss on Azure

Finally, another interesting test would be to change the number of instances that serve the application to verify that effectively balances our site. So we can change the number of instances from the portal or edit the Azure package configuration from Eclipse:

MyAzureProject Azure Properties

Select the Roles option. We click and select Edit WorkerRole1 to change the value:

Properties for WorkerRole1

Hope this helps.

Happy clouding!