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:
In the case of Java, the options that we provide as web server are Tomcat and Jetty:
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:
- 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.
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.
Once back to access the list of available servers, we see that the list has grown and we can select 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…
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).
From this moment begins the download and decompression of JBoss. The last steps for configuring JBoss are:
- Change the value of Home Directory location of our JBoss installation.
- Ensuring that the JDK selected for the server is version 7, because otherwise it will not work correctly.
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:
Mantain the values by default.
In WebContent create a new JSP file called index.jsp, to take it as the default startup document.
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 …
We choose the name of the project (Azure Project) and make sure that the JDK tab has the following configuration:
In the Server tab must select the location of the JBoss server we created earlier:
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:
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:
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…:
To view the site which is displayed on the emulator, just go to the browser and type: http://127.0.0.1:8080/MyJavaHelloWorld:
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;))
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.
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:
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:
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:
Select the Roles option. We click and select Edit WorkerRole1 to change the value:
Hope this helps.
Happy clouding!