How to run a Java application server on a virtual machine
With Windows Azure, you can use a virtual machine to provide server capabilities. As an example, a virtual machine running on Windows Azure can be configured to host a Java application server, such as Apache Tomcat. On completing this guide, you will have an understanding of how to create a virtual machine running on Windows Azure and configure it to run a Java application server.
You will learn:
- How to create a virtual machine.
- How to remotely log in to your virtual machine.
- How to install a JDK on your virtual machine.
- How to install a Java application server on your virtual machine.
- How to create an endpoint for your virtual machine.
- How to open a port in the firewall for your application server.
For purposes of this tutorial, an Apache Tomcat application server will be installed on a virtual machine. The completed installation will result in a Tomcat installation such as the following.

Note To complete this tutorial, you need a Windows Azure account. You can create a free trial account in just a couple of minutes. For details, see Windows Azure Free Trial.
To create a virtual machine
- Log in to the Windows Azure Management Portal.
- Click New.
- Click Virtual machine.
- Click Quick create.
- In the Create virtual machine screen, enter a value for DNS name.
- From the Image dropdown list, select an image, such as Windows Server 2008 R2 SP1.
- Enter a name for the administrator in the User Name field. Remember this name and the password you will enter next, you will use them when you remotely log in to the virtual machine.
- Enter a password in the New password field, and re-enter it in the Confirm field. This is the Administrator account password.
-
From the Location drop down list, select the data center location for your virtual machine. Your screen will look similar to the following.

-
Click Create virtual machine. Your virtual machine will be created. You can monitor the status in the Virtual machines section of the management portal.
To remotely log in to your virtual machine
- Log on to the Management Portal.
- Click Virtual machines.
- Click the name of the virtual machine that you want to log in to.
- Click Connect.
- Respond to the prompts as needed to connect to the virtual machine. When prompted for the administrator name and password, use the values that you provided when you created the virtual machine.
To install a JDK on your virtual machine
You can copy a Java Developer Kit (JDK) to your virtual machine, or install a JDK through an installer.
For purposes of this tutorial, a JDK will be installed from Oracle's site.
- Log in to your virtual machine.
- Within your browser, open http://www.oracle.com/technetwork/java/javase/downloads/index.html.
- Click the Download button for the JDK that you want to download. For purposes of this tutorial, the Download button for the Java SE 6 Update 32 JDK was used.
- Accept the license agreement.
- Click the download executable for Windows x64 (64-bit).
- Follow the prompts and respond as needed to install the JDK to your virtual machine.
To install a Java application server on your virtual machine
You can copy a Java application server to your virtual machine, or install a Java application server through an installer.
For purposes of this tutorial, a Java application server will be installed by copying a zip file from Apache's site.
- Log in to your virtual machine.
- Within your browser, open http://tomcat.apache.org/download-70.cgi.
- Double-click 64-bit Windows zip. (This tutorial used the zip for Tomcat Apache 7.0.27.)
- When prompted, choose to save the zip.
- When the zip is saved, open the folder that contains the zip and double-click the zip.
- Extract the zip. For purposes of this tutorial, the path used was C:\program files\apache-tomcat-7.0.27-windows-x64.
To run the Java application server privately on your virtual machine
The following steps show you how to run the Java application server and test it within the virtual machine's browser. It won't be usable by external computers until you create an endpoint and open a port (those steps are described later).
- Log in to your virtual machine.
- Add the JDK bin folder to the Pathenvironment variable:
- Click Windows Start.
- Right-click Computer.
- Click Properties.
- Click Advanced system settings.
- Click Advanced.
- Click Environment variables.
- In the System variables section, click the Path variable and then click Edit.
- Add a trailing ; to the Path variable value (if there is not one already) and then add c:\program files\java\jdk\bin to the end of the Path variable value (adjust the path as needed if you did not use c:\program files\java\jdk as the path for your JDK installation).
- Press OK on the opened dialogs to save your Path change.
- Set the JAVA_HOMEenvironment variable:
- Click Windows Start.
- Right-click Computer.
- Click Properties.
- Click Advanced system settings.
- Click Advanced.
- Click Environment variables.
- In the System variables section, click New.
- Create a variable named JRE_HOME and set its value to c:\program files\java\jdk\jre (adjust the path as needed if you did not use c:\program files\java\jdk as the path for your JDK installation).
- Press OK on the open dialogs to save your JRE_HOME environment variable.
- Start Tomcat:
You should now see Tomcat running if you run the virtual machine's browser and open http://localhost:8080.
To see Tomcat running from external machines, you'll need to create an endpoint and open a port.
To create an endpoint for your virtual machine
- Log in to the Management Portal.
- Click Virtual machines.
- Click the name of the virtual machine that is running your Java application server.
- Click Endpoints.
- Click Add endpoint.
- In the Add endpoint dialog, ensure Add endpoint is checked and click the Next button.
- In the New endpoint detailsdialog
To open a port in the firewall for your virtual machine
- Log in to your virtual machine.
- Click Windows Start.
- Click Control Panel.
- Click System and Security, click Windows Firewall, and then click Advanced Settings.
-
Click Inbound Rules and then click New Rule.

-
For the new rule, select Port for the Rule type and click Next.

-
Select TCP for the protocol and specify 8080 for the port, and click Next.

-
Choose Allow the connection and click Next.

-
Ensure Domain, Private, and Public are checked for the profile and click Next.

-
Specify a name for the rule, such as HttpIn (the rule name is not required to match the endpoint name, however), and then click Finish.

At this point, your Tomcat web site should now be viewable from an external browser, using a URL of the form http://your_DNS_name.cloudapp.net, where your_DNS_name is the DNS name you specified when you created the virtual machine.
Application lifecycle considerations
- You could create your own application web archive (WAR) and add it to the webapps folder. For example, create a basic Java Service Page (JSP) dynamic web project and export it as a WAR file, copy the WAR to the Apache Tomcat webapps folder on the virtual machine, then run it in a browser.
- This tutorial runs Tomcat through a command prompt where catalina.bat start was called. You may instead want to run Tomcat as a service, a key benefit being to have it automatically start if the virtual machine is rebooted. To run Tomcat as a service, you can install it as a service via the service.bat file in the Apache Tomcat bin folder, and then you could set it up to run automatically via the Services snap-in. You can start the Services snap-in by clicking Windows Start, Administrative Tools, and then Services. If you run service.bat install MyTomcat in the Apache Tomcat bin folder, then within the Services snap-in, your service name will appear as Apache Tomcat MyTomcat. By default when the service is installed, it will be set to start manually. To set it to start automatically, double-click the service in the Services snap-in and set Startup Type to Automatic, as shown in the following.

You'll need to start the service the first time, which you can do through the Services snap-in (alternatively, you can reboot the virtual machine). Close the running occurrence of catalina.bat start if it is still running before starting the service.
Next steps
- Learn about other services, such as Windows Azure Storage, service bus, SQL Database, and more that you may want to include with your Java applications, by viewing the information available at http://www.windowsazure.com/en-us/develop/java/.