How to run a Java application server on a virtual machine created with the classic deployment model
Classic VMs will be retired on March 1, 2023.
If you use IaaS resources from ASM, please complete your migration by March 1, 2023. We encourage you to make the switch sooner to take advantage of the many feature enhancements in Azure Resource Manager.
For more information, see Migrate your IaaS resources to Azure Resource Manager by March 1, 2023.
Azure has two different deployment models for creating and working with resources: Resource Manager and Classic. This article covers using the Classic deployment model. Microsoft recommends that most new deployments use the Resource Manager model. For a Resource Manager template to deploy a webapp with Java 8 and Tomcat, see here.
Starting November 15, 2017, virtual machines will be available only in the Azure portal.
With Azure, you can use a virtual machine to provide server capabilities. As an example, a virtual machine running on Azure can be configured to host a Java application server, such as Apache Tomcat.
After completing this guide, you will have an understanding of how to create a virtual machine running on Azure and configure it to run a Java application server. You will learn and perform the following tasks:
- How to create a virtual machine that has a Java Development Kit (JDK) already installed.
- How to remotely sign in to your virtual machine.
- How to install a Java application server--Apache Tomcat--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.
The completed installation results in Tomcat running on a virtual machine.
To create a virtual machine
Sign in to the Azure portal.
Click Create a resource, click Compute, then click See all in the Featured apps.
Click JDK, click JDK 8 in the JDK pane.
Virtual machine images that support JDK 6 and JDK 7 are available if you have legacy applications that are not ready to run in JDK 8.
In the JDK 8 pane, select Classic, then click Create.
In the Basics blade:
- Specify a name for the virtual machine.
- Enter a name for the administrator in the User Name field. Remember this name and the associated password that follows in the next field. You need them when you remotely sign in to the virtual machine.
- Enter a password in the New password field, and reenter it in the Confirm password field. This password is for the Administrator account.
- Select the appropriate Subscription.
- For the Resource group, click Create new and enter the name of a new resource group. Or, click Use existing and select one of the available resource groups.
- Select a location where the virtual machine resides, such as South Central US.
In the Virtual machine image size blade, select A1 Standard or another appropriate image.
In the Settings blade, click OK. You can use the default values provided by Azure.
In the Summary blade, click OK.
To remotely sign in to your virtual machine
- Log on to the Azure portal.
- Click Virtual machines (classic). If needed, click More services at the bottom left corner under the service categories. The Virtual machines (classic) entry is listed in the Compute group.
- Click the name of the virtual machine that you want to sign in to.
- After the virtual machine has started, a menu at the top of the pane allows connections.
- Click Connect.
- Respond to the prompts as needed to connect to the virtual machine. Typically, you save or open the .rdp file that contains the connection details. You might have to copy the url:port as the last part of the first line of the .rdp file and paste it in a remote sign-in application.
To install a Java application server on your virtual machine
You can copy a Java application server to your virtual machine, or you can install a Java application server through an installer.
This tutorial uses Tomcat as the Java application server to install.
- When you are signed in to your virtual machine, open a browser session to Apache Tomcat.
- Double-click the link for 32-bit/64-bit Windows Service Installer. By using this technique, Tomcat installs as a Windows service.
- When prompted, choose to run the installer.
- Within the Apache Tomcat Setup wizard, follow the prompts to install Tomcat. For the purposes of this tutorial, accepting the defaults is fine. When you reach the Completing the Apache Tomcat Setup Wizard dialog box, you can optionally check Run Apache Tomcat to have Tomcat start now. Click Finish to complete the Tomcat setup process.
To start Tomcat
You can manually start Tomcat by opening a command prompt on your virtual machine and running the command net start Tomcat8.
Once Tomcat is running, you can access Tomcat by entering the URL http://localhost:8080 in the virtual machine's browser.
To see Tomcat running from external machines, you need to create an endpoint and open a port.
To create an endpoint for your virtual machine
- Sign in to the Azure portal.
- Click Virtual machines (classic).
- Click the name of the virtual machine that is running your Java application server.
- Click Endpoints.
- Click Add.
- In the Add endpoint dialog box:
- Specify a name for the endpoint; for example, HttpIn.
- Select TCP for the protocol.
- Specify 80 for the public port.
- Specify 8080 for the private port.
- Select Disabled for the floating IP address.
- Leave the access control list as is.
- Click the OK button to close the dialog box and create the endpoint.
To open a port in the firewall for your virtual machine
- Sign 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 Rule Type, select Port, and then click Next.
- On the Protocol and Ports screen, select TCP, specify 8080 as the Specific local port, and then click Next.
- On the Action screen, select Allow the connection, and then click Next.
- On the Profile screen, ensure that Domain, Private, and Public are selected, and then click Next.
- On the Name screen, 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 website should be viewable from an external browser. In the browser's address window, type 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 web application 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. Next, copy the WAR to the Apache Tomcat webapps folder on the virtual machine, then run it in a browser.
By default when the Tomcat service is installed, it is set to start manually. You can switch it to start automatically by using the Services snap-in. Start the Services snap-in by clicking Windows Start, Administrative Tools, and then Services. Double-click the Apache Tomcat service and set Startup type to Automatic.
The benefit of having Tomcat start automatically is that it starts running when the virtual machine is rebooted (for example, after software updates that require a reboot are installed).
You can learn about other services (such as Azure Storage, service bus, and SQL Database) that you may want to include with your Java applications. View the information available at the Java Developer Center.