In previous post, we had developed a JSP web application and ran in local Tomcat server. In this post, we will see how to host this application in Azure environment.
Install Windows Azure SDK
Step 1: The first requirement is to install Windows Azure SDK in the development system. So open the browser and access the following url.
http://www.microsoft.com/web/gallery/install.aspx?appid=WindowsAzureSDK
It will open up a page with Install Now button. It is a Web Installer, will download and install all the required software for developing and running Windows Azure application on your development system. So you should be ready for all pre requisite installation in your system when clicking the button.
Step 2: Click Install Now button. It will popup to download some KB of file (will be 97.8 KB) with Save and Cancel button. Save the file somewhere and run it.
Press Install to install the required components.
The Web Installer will scan your system and tell you what are the missing installation required and to install. Press I Accept button to install all.
Step 3: Once installation over, it will tell you what are all the things are installed.
Note: The list may vary depends of your system.
Step 4: Exit from Web Installer.
Installing Windows Azure Toolkit for Java
Step 1: Open the eclipse and select Help -> Install New Software… menu.
It will open up Available Software dialog for getting input what to install.
Step 2: Enter the following URL in the Work with text box and press enter. (You can also add in the repository)
http://dl.windowsazure.com/eclipse
The eclipse software will search the available software in the URL and list Windows Azure Toolkit for Java in the table.
Step 3: Select the Windows Azure Toolkit for Java checkbox and press Next.
Step 4: The eclipse will list of software will install in the next window. Review the applications and press Next.
Step 5: Accept the terms of the license agreements and press Finish.
The Windows Azure Toolkit for Java will be installed on the system.
Step 6: Once the installation over, it popup a dialog to confirm to restart your system. Press Restart Now if you are ready to restart.
Adding Windows Azure Project in the Workspace
As we have installed Windows Azure Plugin for eclipse, we can able to create Windows Azure Projects to target to Azure environment.
Step 1: Select File -> New -> Others menu.
Eclipse will open New doalog box.
Step 2: Select Windows Azure Project from the tree and press Next.
Step 3: Enter the Project name (Ex: JavaOnAzurePOC) in the New Windows Azure Project dialog and press Finish.
Eclipse will add a new project in the workspace.
Adding JDK and Tomcat files to the project
As we are running this project in Azure environment, the system will not have anything installed related Java. The server is plain Windows Server 2008 R2, IIS, .NET runtime and some security patches installed. So we need to provide the JDK and Apache Tomcat server (as I use Tomcat in this exercise) files to the server with the package and install before the Java application runs using Startup Task.
To know more about what is startup task and how it is useful for Azure, please look at this link.
Step 1: We have to get the JDK files as zip file. So open the Java installation folder (if you installed with default location it would be C:\Program Files\Java\ jdk1.x.x_xx).
Make a copy of the folder and change the folder name to jdk. Right click the folder and select Send to -> Compressed (zipped) folder.
Note: You can remove the src zip file under this folder before zipping to reduce the overall Azure package file.
Step 2: It will create a jdk.zip file. Copy the file to WebRole1\approot folder of Windows Azure (JavaOnAzurePOC) project.
Step 3: We also required Tomcat server to be install on starting up the role. But in this exercise I am planning to download Apache Tomcat files from internet and install on the fly using the script file. So I don’t require zipping the Tomcat folder and adding it in to my project.
Note: If you choose to upload tomcat server files - that can be done as the same way did for jdk. For that, open the apache-tomcat-7.x.xx (Ex: apache-tomcat-7.0.26) folder in your development system to make a copy to tomcat folder and zip to tomcat7.zip the same way. Copy the file to WebRole1\approot folder of Windows Azure (JavaOnAzurePOC) project.
Also please note, when I try shipping tomcat7.zip with the package it was not working. So I always go for download and install from internet on the fly.
Publishing JSP application WAR to Azure project
The main purpose of this exercise is to access the JSPSampleApp project into Windows Azure environment. So we need to bundle the WAR file of the JSP project within Azure project.
Step 1: Delete the HelloWorld.war file under approot folder of Azure project as we don’t want them.
Step 2: Right click JSPSampleApp project and select Export -> WAR file.
It will open WAR Export dialog window.
Step 3: Press the Browse button next to Destination input and select the approot folder of the JavaOnAzurePOC project. (Ex: C:\Users\Administrator\workspace\JavaOnAzurePOC\WorkerRole1\approot)
Step 4: Right click the approot folder and refresh.
Configuring the Startup Script
Next job is to change the startup script to install jdk and tomcat server files by unzipping the files we copied.
Step 1: The startup scripts are already given in the project under samples folder for each servers such as Tomcat, GlassFish, JBoss etc.. So open the samples folder and copy the scripts from the corresponding server you are using (in this case copying startupApacheTomcat7.txt).
Step 2: Right click the startup.cmd file under approot and select Open With -> Text Editor.
I will open the script in text editor.
Step 3: Clear all the existing script in the startup.cmd file and paste the copied scripts from startupApacheTomcat7.txt file.
Step 4: Change the SET WAR_NAME variable value to the war file name just exported i.e., JSPSampleApp.war.
Step 5: If you required to choose to download and install Apache Tomcat server from internet, uncomment the below statement.
cscript /NoLogo "util\download.vbs" "http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.zip" "tomcat7.zip"
Run the Windows Azure Application locally
Now we have completed all the works for targeting Windows Azure environment. We can test this application locally.
Step 1: If we run the application in development fabric, the packagetype in the package.xml file must be set to local for windowsazurepackage node. So make sure the packagetype property is local.
Step 2: Build the project by selecting Project -> Build All.
The output of the build must be successful.
Step 3: Run (double click) the RunInEmulator command file from the emulatorTools folder (located in JavaOnAzurePOC project - C:\Users\Administrator\workspace\JavaOnAzurePOC\emulatorTools).
It will open some command window to install jdk and Apache Tomcat server and run the emulator.
Step 4: Once you get java.exe is running… message in the Windows Azure Computer Emulator window, you can start accessing the application url from the browser.
The browser will show Apache Tomcat information in the http://localhost:8080 url. To access the JSPSampleApp application we need to add the war file name at the end of the url.
Step 5: Tp access our application, use http://localhost:8080/JSPSampleApp url.
Step 6: To shut down the emulator, open the emulatorTools folder under deploy folder and run the (double click) then ResetEmulator.cmd file.
Note: To deploy this JSP application, we must able to run the application under development environment successfully.
Deploying JSP Application in Windows Azure.
Step 1: For deploying the windows azure application, the application must build with packagetype="cloud" in the package.xml file.
So, Open the package.xml file and change the packagetype property of windowsazurepackage node to cloud.
Step 2: Build the project by selecting Project -> Build All.
Once deployment succeeded it will produce WindowsAzurePackage.cspkg and ServiceConfiguration.cscfg files under deploy folder of JavaOnAzurePOC project.
Step 3: For deploying this package to windows azure, it require a valid certificate to be uploaded with. The certificate already given in the cert folder under the Windows Azure project folder. So create a hosted service without uploading package (with Do not deploy option) and upload the certificate for that hosted service (Password for the certificate is Password1).
Step 4: Once hosted service and certificate is uploaded, deploy the package and configuration file either staging or production environment.
Step 5: Once deployment succeded, access the url as below.
If you face any issue, please comment on this blog. I will try to solve the issue.
download the source code (workspace) of this POC here.
Install Windows Azure SDK
Step 1: The first requirement is to install Windows Azure SDK in the development system. So open the browser and access the following url.
http://www.microsoft.com/web/gallery/install.aspx?appid=WindowsAzureSDK
It will open up a page with Install Now button. It is a Web Installer, will download and install all the required software for developing and running Windows Azure application on your development system. So you should be ready for all pre requisite installation in your system when clicking the button.
Step 2: Click Install Now button. It will popup to download some KB of file (will be 97.8 KB) with Save and Cancel button. Save the file somewhere and run it.
Screenshot from IE 9.0 browser |
The Web Installer will scan your system and tell you what are the missing installation required and to install. Press I Accept button to install all.
Step 3: Once installation over, it will tell you what are all the things are installed.
Note: The list may vary depends of your system.
Step 4: Exit from Web Installer.
Installing Windows Azure Toolkit for Java
Step 1: Open the eclipse and select Help -> Install New Software… menu.
It will open up Available Software dialog for getting input what to install.
Step 2: Enter the following URL in the Work with text box and press enter. (You can also add in the repository)
http://dl.windowsazure.com/eclipse
The eclipse software will search the available software in the URL and list Windows Azure Toolkit for Java in the table.
Step 3: Select the Windows Azure Toolkit for Java checkbox and press Next.
Step 4: The eclipse will list of software will install in the next window. Review the applications and press Next.
Step 5: Accept the terms of the license agreements and press Finish.
The Windows Azure Toolkit for Java will be installed on the system.
Step 6: Once the installation over, it popup a dialog to confirm to restart your system. Press Restart Now if you are ready to restart.
Adding Windows Azure Project in the Workspace
As we have installed Windows Azure Plugin for eclipse, we can able to create Windows Azure Projects to target to Azure environment.
Step 1: Select File -> New -> Others menu.
Eclipse will open New doalog box.
Step 2: Select Windows Azure Project from the tree and press Next.
Step 3: Enter the Project name (Ex: JavaOnAzurePOC) in the New Windows Azure Project dialog and press Finish.
Eclipse will add a new project in the workspace.
Adding JDK and Tomcat files to the project
As we are running this project in Azure environment, the system will not have anything installed related Java. The server is plain Windows Server 2008 R2, IIS, .NET runtime and some security patches installed. So we need to provide the JDK and Apache Tomcat server (as I use Tomcat in this exercise) files to the server with the package and install before the Java application runs using Startup Task.
To know more about what is startup task and how it is useful for Azure, please look at this link.
Step 1: We have to get the JDK files as zip file. So open the Java installation folder (if you installed with default location it would be C:\Program Files\Java\ jdk1.x.x_xx).
Make a copy of the folder and change the folder name to jdk. Right click the folder and select Send to -> Compressed (zipped) folder.
Note: You can remove the src zip file under this folder before zipping to reduce the overall Azure package file.
Step 2: It will create a jdk.zip file. Copy the file to WebRole1\approot folder of Windows Azure (JavaOnAzurePOC) project.
Step 3: We also required Tomcat server to be install on starting up the role. But in this exercise I am planning to download Apache Tomcat files from internet and install on the fly using the script file. So I don’t require zipping the Tomcat folder and adding it in to my project.
Note: If you choose to upload tomcat server files - that can be done as the same way did for jdk. For that, open the apache-tomcat-7.x.xx (Ex: apache-tomcat-7.0.26) folder in your development system to make a copy to tomcat folder and zip to tomcat7.zip the same way. Copy the file to WebRole1\approot folder of Windows Azure (JavaOnAzurePOC) project.
Also please note, when I try shipping tomcat7.zip with the package it was not working. So I always go for download and install from internet on the fly.
Publishing JSP application WAR to Azure project
The main purpose of this exercise is to access the JSPSampleApp project into Windows Azure environment. So we need to bundle the WAR file of the JSP project within Azure project.
Step 1: Delete the HelloWorld.war file under approot folder of Azure project as we don’t want them.
Step 2: Right click JSPSampleApp project and select Export -> WAR file.
It will open WAR Export dialog window.
Step 3: Press the Browse button next to Destination input and select the approot folder of the JavaOnAzurePOC project. (Ex: C:\Users\Administrator\workspace\JavaOnAzurePOC\WorkerRole1\approot)
Step 4: Right click the approot folder and refresh.
Configuring the Startup Script
Next job is to change the startup script to install jdk and tomcat server files by unzipping the files we copied.
Step 1: The startup scripts are already given in the project under samples folder for each servers such as Tomcat, GlassFish, JBoss etc.. So open the samples folder and copy the scripts from the corresponding server you are using (in this case copying startupApacheTomcat7.txt).
Step 2: Right click the startup.cmd file under approot and select Open With -> Text Editor.
I will open the script in text editor.
Step 3: Clear all the existing script in the startup.cmd file and paste the copied scripts from startupApacheTomcat7.txt file.
Step 4: Change the SET WAR_NAME variable value to the war file name just exported i.e., JSPSampleApp.war.
Step 5: If you required to choose to download and install Apache Tomcat server from internet, uncomment the below statement.
cscript /NoLogo "util\download.vbs" "http://archive.apache.org/dist/tomcat/tomcat-7/v7.0.22/bin/apache-tomcat-7.0.22.zip" "tomcat7.zip"
Run the Windows Azure Application locally
Now we have completed all the works for targeting Windows Azure environment. We can test this application locally.
Step 1: If we run the application in development fabric, the packagetype in the package.xml file must be set to local for windowsazurepackage node. So make sure the packagetype property is local.
Step 2: Build the project by selecting Project -> Build All.
The output of the build must be successful.
Step 3: Run (double click) the RunInEmulator command file from the emulatorTools folder (located in JavaOnAzurePOC project - C:\Users\Administrator\workspace\JavaOnAzurePOC\emulatorTools).
It will open some command window to install jdk and Apache Tomcat server and run the emulator.
Step 4: Once you get java.exe is running… message in the Windows Azure Computer Emulator window, you can start accessing the application url from the browser.
The browser will show Apache Tomcat information in the http://localhost:8080 url. To access the JSPSampleApp application we need to add the war file name at the end of the url.
Step 5: Tp access our application, use http://localhost:8080/JSPSampleApp url.
Step 6: To shut down the emulator, open the emulatorTools folder under deploy folder and run the (double click) then ResetEmulator.cmd file.
Note: To deploy this JSP application, we must able to run the application under development environment successfully.
Deploying JSP Application in Windows Azure.
Step 1: For deploying the windows azure application, the application must build with packagetype="cloud" in the package.xml file.
So, Open the package.xml file and change the packagetype property of windowsazurepackage node to cloud.
Step 2: Build the project by selecting Project -> Build All.
Once deployment succeeded it will produce WindowsAzurePackage.cspkg and ServiceConfiguration.cscfg files under deploy folder of JavaOnAzurePOC project.
Step 3: For deploying this package to windows azure, it require a valid certificate to be uploaded with. The certificate already given in the cert folder under the Windows Azure project folder. So create a hosted service without uploading package (with Do not deploy option) and upload the certificate for that hosted service (Password for the certificate is Password1).
Step 4: Once hosted service and certificate is uploaded, deploy the package and configuration file either staging or production environment.
Step 5: Once deployment succeded, access the url as below.
If you face any issue, please comment on this blog. I will try to solve the issue.
download the source code (workspace) of this POC here.
0 Responses to “Publishing Java Application in Windows Azure Environment - Part 2”
Post a Comment