Floating FB popout byF5debug

Developing a Hello World Java Application and Deploying it in Windows Azure - Part II

In this article we will see the steps involved in deploying the WAR created in the first part of this series to the compute emulator and to windows azure platform first in staging environment and later promote it to production. We will also have a look at different options available in Windows Azure management portal to deploy and maintain the deployed application.


Introduction

In Part I of this series we had seen the steps to install Windows Azure plugin for eclipse and we created a simple HelloWorld java project. We also create an Azure project using the installed plugin and made the WAR file ready for deployment.          [more]

In this article we will see the steps involved in deploying the WAR created to the compute emulator and to windows azure platform first in staging environment and later promote it to production. We will also have a look at different options available in Windows Azure management portal to deploy and maintain the deployed application.

Steps

In the last article, we saw how to export HelloWorld.war to the azure project. Now we will see how to build the azure project that we created.

For this we should copy over zips of your JDK and server to the approot folder. The file structure within the zip file impacts how the startup.cmd script is going to be used. If the zip files are created as mentioned below then no change will be needed in startup.cmd

File structure within the JDK zip:

JDK zip should contain a root folder named jdk and inside this folder will be your binaries, libraries, etc.

File Structure within the Server zip:

Application Server zip should contain server name with version as the root folder which will in turn contain rest of the binaries for the application server.

Copy both the zip files and paste it under HelloWorldAzureProject /WorkerRole1/approot in the project explorer. Your Azure project should now look as shown in the screen below.

clip_image001

Next, we need to customize our start up script. Under Samples folder in HelloWorldAzureProject you can see sample start up scripts for various application servers. Since we used tomcat for the purpose of this tutorial, copy the contents of startupApacheTomcat7.txt and paste it in the startup.cmd under HelloWorldAzureProject /WorkerRole1/approot/startup.cmd.

If you are using a different server name other than the value specified in SET SERVER_DIR_NAME=apache-tomcat-7.0.22, change the value appropriately.

Also ensure the zip files matches with the names specified in the following lines of the start-up script.

1.cscript /NoLogo util\unzip.vbs jdk.zip "%CD%"

2.cscript /NoLogo util\unzip.vbs tomcat7.zip "%CD%"

Save the start-up script after changes, if any.

Select HelloWorldAzureProject from the project explorer. Click on Project -> Build Project as shown in the screen below.

clip_image002

Ensure the build is successful from the Console window in Eclipse as shown in the screen below.

clip_image003

Steps to deploy application to the compute emulator

In the project explorer in eclipse, expand HelloWorldAzureProject and expand emulatorTools. Double click on RunInEmulator.cmd. This will deploy your application to the compute emulator. You will be prompted to allow this command to make changes to your computer. Click on Yes.

Examine your compute emulator UI for any issues in the project. If your project does not have any issues then the emulator UI looks as shown in the screen below.

clip_image004

Start your browser and use the URL http://localhost:8080/HelloWorld. You should see the output as shown in the screen below.

clip_image005

You can stop your application from running by either using the menu options in the compute emulator UI or by running RunInEmulator.cmd from eclipse under emulatorTools in HelloWorldAzureProject.

Steps to deploy application to Windows Azure

To prepare your application for deployment to the cloud, from the project explorer in eclipse, right click on HelloWorldAzureProject and click Properties as shown in the screen below.

clip_image006

In the Properties dialog that appears, select Windows Azure from the left pane, select Deployment to Cloud in the Build For drop down and click on OK as shown in the screen below.

clip_image007

For the purpose of this tutorial we will turn off Remote access for the Windows Azure project. To do this, expand Windows Azure in the Project Properties dialog and click Remote Access. In the Remote access dialog that appears, uncheck the Enable all roles to accept Remote Desktop connections with these login credentials and click on OK as shown in the screen below.

clip_image008

Click on Project -> Build All in eclipse and ensure the build runs successfully.

In the Project Explorer, expand HelloWorldAzureProject and expand Deploy. You will see three files under deploy. ServiceConfiguration.cscfg and WindowsAzurePackage.cspkg are the files that needs to be uploaded in the Windows Azure Management Portal. WindowsAzurePortal.url is the shortcut to the Windows Azure Management Portal.

clip_image009

Double click on WindowsAzurePortal.url. This will open up the Windows Azure Management Portal.

Log in to the Windows Azure Management Portal and click on Hosted Services, Storage Accounts & CDN tab as shown in the screen below.

clip_image010

Click New Hosted Service button at the top left corner as shown in the screen below.

clip_image011

Create a New Hosted Service pop up appears.

Select the subscription to be used for this service and enter a name for this service. This name is used to distinguish your services within this portal for the specified subscription.

Enter the URL for this service. The portal ensures that this URL is unique within the Azure platform and that it is not in use by anyone else's service.

Select Region from the dropdown available, say for example Anywhere Asia.

Select Deploy to stage environment in the deployment options. Also ensure Start after successful deployment is checked.

Specify a deployment name.

Click on Browse Locally next to Package location text box and navigate to <your project location>\HelloWorldAzureProject\deploy\ and select WindowsAzurePackage.cspkg.

Click on Browse Locally next to Configuration file text box and navigate to <your project location>\HelloWorldAzureProject\deploy\ and select ServiceConfiguration.cscfg.

With all these details entered in the Create New Hosted Service pop up, the screen looks as shown below.

clip_image012

You will receive a warning since there is only one worker role defined. For the purpose of this tutorial we will ignore this warning. So, click on Yes.

The status of the deployment can be verified under Hosted Services section under Windows Azure Management Portal as shown in the screen below.

clip_image013

You can now use URL http://e71e15c2150f42a9b54738c336c02e85.cloudapp.net/HelloWorld to access the deployed application.

With this we have deployed our application in the staging environment in Windows Azure. Now let us see how to promote this application to production environment.

Steps to promote this application to production environment

In the Windows Azure Management Portal click on Swap VIP as shown in the screen below.

clip_image014

Swap VIPs dialog pops up as shown in the screen below. Click on OK to proceed further.

clip_image015

The environment of the Hosted Service now changes from Staging to Production as shown in the screen below.

clip_image016

This completes the process of promoting an application from staging to production environment in Windows Azure Platform.

Steps to upgrade our application and deploying it in Windows Azure Cloud

Now we will make a minor change in our application and deploy the newer version in Windows Azure platform.

In eclipse, open index.jsp under WebContent in the HelloWorld project. Include <b>Version 2.0</b> inside <body> tags in the jsp as shown below.

1.<body>

2.<b>Hello World!</b>

3.<b>Version 2.0</b>

4.</body>

Save index.jsp.

To export the latest HelloWorld.war to the HelloWorldAzureProject, right click on the HelloWorld project in the project explorer and click on Export -> WAR file. In the destination text box, browse to <your project location>\HelloWorldAzureProject\WorkerRole1\approot. Check Overwrite Existing File option in the WAR Export dialog and click on Finish.

Click on Project -> Build All to build our changes and ensure the build is successful.

In Windows Azure Management Portal, click on Hosted Services, Storage Accounts & CDN and click on Production deployments as shown in the screen below.

clip_image017

Click on HelloWorld Deployment and click on Upgrade icon as shown in the screen below.

clip_image018

Upgrade Deployment dialog pops up.

Click on Browse Locally next to Package location text box and navigate to <your project location>\HelloWorldAzureProject\deploy\ and select WindowsAzurePackage.cspkg.

Click on Browse Locally next to Configuration file text box and navigate to <your project location>\HelloWorldAzureProject\deploy\ and select ServiceConfiguration.cscfg.

With these details entered Upgrade Deployment screen looks as shown below.

clip_image019

Click on OK to proceed further. A warning pops up as before. Click on Yes to ignore the warning for the purpose of this tutorial. Wait till the deployment is ready.

Now click on the DNS URL http://helloworldtutorial.cloudapp.net/HelloWorld/ and we can see the latest changes (Version 2.0) as shown in the screen below.

clip_image020

Conclusion

In this article we saw the steps involved in deploying the java application to the compute emulator and then to the Windows Azure Platform. Steps for promoting a deployment from staging environment to production environment are explained. We also saw how to upgrade our deployment in future after additional changes in our java application.

Bottom of Form

.

About Author: Karthikeyan Anbarasan, Microsoft MVP (Most Valuable Professional) in ASP.NET/IIS Architecture. He is the Founder and Chief Editor of the www.f5debug.net website and has authored books on Windows Phone and Business Intelligence(SSIS). He is also a Passionate Speaker and a Blogger on Microsoft Technologies.

You can Join Me On: Facebook, Twitter, Google Plus, LinkedIn

Comments (1) -

Pramod
Pramod
8/11/2012 11:38:09 AM #

Hi. I've followed every step you've explained except zipping the jdk and the server as they are already added in the approot folder by eclipse. When im uploading in the management portal it is uploading till 82% and then it says "upload failed check your network connection and try again later". This happened twice. And it is also taking 2hrs for uploading 80%. Please help me out. Im struck with this since 2 day's

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Recent Posts

Random Posts

Most Viewed

URL Shortner

Create your own short urls!!!

Site Counter

free counters

Disclaimer

This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet. I have documented my personal experience on this blog.

Protected by Copyscape Web Plagiarism Finder

Site Meter