JavaRunning Java Applications on Windows Azure

Running Java Applications on Windows Azure

Developer.com content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

Windows Azure supports running applications in a variety of frameworks.  In this article, we explore how we can run Java applications on Windows Azure.

Overview

Microsoft’s cloud computing platform supports running applications written in a variety of languages on multiple frameworks. You can write applications in .NET, PHP, Node.js, and Java. In this article, we will walk through the steps to create a Java application that can run on Windows Azure.

Windows Azure and Java

To improve adoption of Windows Azure, Microsoft had provided a robust set of tools to ease the effort of getting Java applications running on the cloud. These tools are packaged as Windows Azure SDK for Java, which includes Windows Azure emulator and plugins to enable Azure development inside of the Eclipse IDE, as well as client libraries for Java. For the technically inclined, Microsoft has also released the source code for the above-mentioned.

To get started, a developer needs to install Windows Azure SDK v1.1. It is available from http://www.microsoft.com/web/gallery/install.aspx?appid=WindowsAzureSDK.

Next, we need to download the Windows Azure SDK for Java at http://go.microsoft.com/fwlink/?LinkID=234491

There are two options to download the Windows Azure Libraries for Java – manually or using Apache Maven.

To download the SDK manually, you need to download a bunch of files. Here is the complete list of files that need to be downloaded.

 

Windows Azure Libraries for Java JAR

http://go.microsoft.com/fwlink/?LinkID=236226

Commons-lang3-3.1.jar (dependency files)

Download from search.maven.org

Commons-logging-1.1.1.jar (dependency files)

Download from search.maven.org

Jackson-core-asl-1.8.3.jar (dependency files)

Download from search.maven.org

Jackson-jaxrs-1.8.3.jar (dependency files)

Download from search.maven.org

jackson-mapper-asl-1.8.3.jar (dependency files)

Download from search.maven.org

jackson-xc-1.8.3.jar (dependency files)

Download from search.maven.org

javax.inject-1.jar (dependency files)

Download from search.maven.org

jaxb-impl-2.2.3-1.jar (dependency files)

Download from search.maven.org

jersey-client-1.10-b02.jar (dependency files)

Download from search.maven.org

jersey-core-1.10-b02.jar (dependency files)

Download from search.maven.org

jersey-json-1.10-b02.jar (dependency files)

Download from search.maven.org

jettison-1.1.jar (dependency files)

Download from search.maven.org

stax-api-1.0.1.jar (dependency files)

Download from search.maven.org

javax.mail.jar (dependency files)

Download from search.maven.org

These files are available as a single zip file at http://go.microsoft.com/fwlink/?LinkId=253887&clcid=0x409 under the Apache License.

Next, we need to get the Windows Azure Plugin for Eclipse. For that, select the Help -> “Install New software” option on the Eclipse IDE.

Get the Windows Azure Plugin for Eclipse
Get the Windows Azure Plugin for Eclipse

Type http://dl.msopentech.com/eclipse in the “Works with” field.

Select “Windows Azure Toolkit for Java” and click “Next”.

Select "Windows Azure Toolkit for Java"
Select “Windows Azure Toolkit for Java”

Confirm the items to be installed.

Accept the license terms to start the installation.

After the installation is complete, Eclipse will prompt to restart.

Hands-On

Let us create a very simple Java application, which we will host on Windows Azure. Start Eclipse Enterprise Edition and choose a new “Dynamic Web Project”, and name the project JavaDemo and click Finish.

Dynamic Web Project
Dynamic Web Project

Add a new JSP file titled “home.jsp”  from the content menu for “WebContent” folder inside the Project Explorer.

WebContent folder
WebContent folder

Create a new JSP file
Create a new JSP file

Open home.jsp and in the body markup; add some HTML text.

// home.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
Hello Azure from Java!!! Visit Developer.com for more articles.
</body>
</html>

Now, we will create a Windows Azure project called JavaAzureDemo. Right click JavaDemo -> Windows Azure > Other . Search for Azure and select “Windows Azure Project” wizard. Type “JavaAzureDemo” in the project name and click Finish to create the project.

Select "Windows Azure Project"
Select “Windows Azure Project”

Enter the name of the Project as “JavaAzureDemo” and click Finish.

New Windows Azure Deployment Project
New Windows Azure Deployment Project

Windows Azure Project: Roles
Windows Azure Project: Roles

Next the wizard prompts to enter the location of JDK and a webserver and click Finish.

Note that you need to provide the location of the binaries on your PC in the “Directory” fields.

Provide the location of the binaries
Provide the location of the binaries

Once the Azure Deployment Project is successfully created, click the “Run in Windows Azure emulator” button in the Eclipse toolbar.

Run in Windows Azure Emulator
Run in Windows Azure Emulator

Once the deployment project kicks off, it takes several minutes for the process to complete.  Once the Apache Catalina server starts, you can open http://localhost:8080/JavaDemo/ and see the Java web application we have created. We now have a Java Application running on Windows Azure Emulator.

Moving to the Cloud – Deploying to Windows Azure

To deploy to the cloud, we can a build a package by clicking on “Build Cloud Package for Windows Azure”

Build Cloud Package for Windows Azure
Build Cloud Package for Windows Azure

Once the package is built successfully, a “Windows Explorer” window opens, which shows the binaries created as a result of the build.

A Windows Explorer window opens
A Windows Explorer window opens

The deployment binaries include “Service Configuration” and the WindowsAzurePackage”.

We can then deploy these bits through the Windows Azure portal. A link to the portal (https://windows.azure.com/default.aspx) is also created.

Summary

In this article, we learned how to create a Java application that can run on Windows Azure. I hope you have found the information useful.

About the author

Vipul Patel is a Program Manager currently working at Amazon Corporation. He has formerly worked at Microsoft in the Lync team and in the .NET team (in the Base Class libraries and the Debugging and Profiling team). He can be reached at vipul_d_patel@hotmail.com

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories