SALES: 1-800-867-1380

Using the Azure Service Runtime Library in JSP

Updated: March 10, 2015

The following steps show you how to create and deploy a basic JSP application to Azure using the Azure Toolkit for Eclipse. A JSP example is shown for simplicity, but highly similar steps would be appropriate for a Java servlet, as far as Azure deployment is concerned.

The application will use functionality from the Azure Service Runtime library and will look similar to the following:

Hello World with Service Runtime

  1. Add the Azure Service Runtime library to your build path. Within Eclipse’s Project Explorer, right-click the MyHelloWorld project and click Properties.

  2. In the left-hand pane of the Properties dialog, click Java Build Path.

  3. Click the Libraries tab, and then click Add Library.

  4. In the Add Library dialog, click Package for Azure Libraries for Java and then click Next.

  5. Check Include in the project deployment assembly, and then click Finish.

  6. Click OK to close the Properties dialog.

  7. Modify the code in index.jsp, to include an import statement for the Service Runtime library, and also add in some functionality that uses this library. The following shows an index.jsp file that includes the import statement, and includes calls into the Service Runtime library.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1" import="*, java.util.Map" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
     <b>Hello World!</b>
     <p>RoleEnvironment.isEmulated() returned <%=RoleEnvironment.isEmulated() %>.</p>
     <p>The ID of the RoleInstance is <%= RoleEnvironment.getCurrentRoleInstance().getId() %>.</p>
     <p>The name of the Role is <%= RoleEnvironment.getCurrentRoleInstance().getRole().getName() %>.</p>
        Map<String, RoleInstanceEndpoint> mapEndpoints = 
        for (Map.Entry<String, RoleInstanceEndpoint> entry : mapEndpoints.entrySet())
             out.println("The endpoint named '" + entry.getKey() + 
                 "' has value " + entry.getValue().getIpEndPoint().getAddress().getHostAddress() + ".");

    The page directive includes the import statement for the Service Runtime classes (as well as for java.util.Map, because one of the methods, RoleInstance.getInstanceEndpoints, returns a Map object). Several other Service Runtime methods are used. For example, RoleEnvironment.isEmulated returns a value that indicates whether the role environment is running in the compute emulator, and RoleEnvironment.getCurrentRoleInstance returns a RoleInstance object that represents the role instance in which the code is running.

  8. Save index.jsp.

  9. Windows only: To launch your application in the Azure emulator, click the Run in Azure Emulator icon in the Azure toolbar. For additional information on running in the Azure emulator, see Creating a Hello World Application for Azure in Eclipse. That topic also describes how to deploy your application to Azure.

For additional information about the Service Runtime package, and other packages from Azure Libraries for Java, see

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2015 Microsoft