Export (0) Print
Expand All

Creating a Hello World Application for Azure in Eclipse

Updated: September 25, 2014

The following steps show you how to create and deploy a basic JSP application to Azure using the Azure Toolkit for Eclipse with Java (by Microsoft Open Technologies). 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 look similar to the following:

Deployed Hello World

  1. First, we’ll start off with creating a Java project. Start Eclipse. Within Eclipse, at the menu click File, click New, and then click Dynamic Web Project. (If you don’t see Dynamic Web Project listed as an available project after clicking File, New, then do the following: click File, click New, click Project…, expand Web, click Dynamic Web Project, and click Next.) For purposes of this tutorial, name the project MyHelloWorld. (Ensure you use this name, subsequent steps in this tutorial expect your WAR file to be named MyHelloWorld). Your screen will appear similar to the following:

    Create Web Project

    Click Finish.

  2. Within Eclipse’s Project Explorer view, expand MyHelloWorld. Right-click WebContent, click New, and then click JSP File.

  3. In the New JSP File dialog, name the file index.jsp. Keep the parent folder as MyHelloWorld/WebContent, as shown in the following:

    Create JSP File

    Click Next.

  4. In the Select JSP Template dialog, for purposes of this tutorial select New JSP File (html) and click Finish.

  5. When the index.jsp file opens in Eclipse, add in text to display Hello World! within the existing <body> element. Your updated <body> content should appear as the following:

    <body>
      <b><% out.println("Hello World!"); %></b>
    </body>
    

    Save index.jsp.

  6. Now we’ll create an Azure deployment project. As a shortcut, in Eclipse’s Project Explorer, right-click the MyHelloWorld project, click Azure, and then click Package for Azure.

    (As an alternative, you can click the New Azure Deployment Project button, New Windows Azure deployment project, in the toolbar, or you can use the menu: Within Eclipse, at the menu click File, click New, and then click Azure Deployment Project. If you don’t see Azure Deployment Project listed as an available project after clicking File, New, then do the following: click File, click New, click Project…, expand Azure Deployment Project, click Azure Deployment Project, and click Next. In this case, you will also need to add a reference to your application as part of the new project wizard.)

    For purposes of this tutorial, name the project MyAzureProject, and click Next.

  7. Within the Azure Deployment Project dialog:

    1. Click the JDK tab. In the Emulator deployment section, click Use the JDK from this file path for testing locally. If the JDK installation location that you want to use is not selected automatically, click the Browse button, and using the browse control, select the desired directory location of the JDK to use with your deployment.

    2. In the Cloud deployment section of the dialog, select the Deploy my local JDK (auto-upload to cloud storage) option. Alternatively, to speed up the deployment process, you may specify one of the third party JDKs provided on Azure by selecting the Deploy a 3rd party JDK package available on Azure option instead.

    3. For the URL and Storage account values, use the default value of (auto). This means that the same storage account will be used for the JDK upload as the one you select for your deployment in the Publish to Azure dialog.

    4. Your populated JDK dialog will now look similar to the following.

      New Windows Azure Deployment Project dialog
      noteNote
      The URL of the uploaded JDK is generated automatically based on the name of the JDK’s installation directory. As long as a file at that exact URL location exists, it will not be automatically uploaded again, regardless of whether its contents have changed. If you change the local JDK setting to point to a different local directory, then a new ZIP file generated from that directory will be uploaded.

    5. Click the Server tab. In the Emulator deployment section, click Use the server from this file path for testing locally and select the installation directory on your computer of an application server of your choice to use with your deployment. If you use Tomcat 6 or 7, GlassFish OSE 3 or OSE 4, JBoss 6 or 7, or Jetty 7, 8 or 9, the server type will automatically be detected and shown in the dropdown shown below. (If the server type is not recognized, do not select a server here but instead manually enter your server and application deployment logic in your startup.cmd file.)

    6. Similar to as done for the JDK, in the Cloud deployment section of the dialog, select the Deploy my local server (auto-upload to cloud storage) option and specify (auto) as the URL and as the storage account.

      Your Server dialog will now look similar to the following.

      Server tab
    7. Click the Applications tab. You will see MyHelloWorld.war already listed if you started this wizard from your MyHelloWorld project’s context menu Package for Azure command.

    8. Your Applications dialog will now look similar to the following.

      Applications tab
    9. [Optional] Click Next to set options for Session Affinity, Caching, or Remote Debugging, as shown in the following.

      Windows Azure deployment project optional features
    10. Click Finish to close the Azure Deployment Project dialog.

  1. In Eclipse’s Project Explorer, click MyAzureProject.

  2. In the Eclipse toolbar, click the Run in Azure Emulator button, Run in Windows Azure emulator. If the Run in Azure Emulator button is not enabled, ensure that MyAzureProject is selected in Eclipse’s Project Explorer, and ensure that Eclipse’s Project Explorer has focus as the current window.

    This will first start a full build of your project and then launch your Java web application in the compute emulator. (Note that depending on your computer’s performance characteristics, the first build may take between a few seconds to a few minutes, but subsequent builds will get faster.) After the first build step has been completed, you will be prompted by Windows User Account Control (UAC) to allow this command to make changes to your computer. Click Yes.

    ImportantImportant
    If you do not see the UAC prompt, check the Windows taskbar for the UAC icon and click it first. Sometimes the UAC prompt does not show up as a topmost window, but is visible only as a taskbar icon.

    Examine the output of the compute emulator UI to determine if there are any issues with your project. Depending on the contents of your deployment, it may take a couple minutes for your application to be fully started within the compute emulator.

  3. Start your browser and use the URL http://localhost:8080/MyHelloWorld as the address (the MyHelloWorld portion of the URL is case-sensitive). You should see your MyHelloWorld application (the output of index.jsp), similar to the following image:

    Hello World in Compute Emulator

When you are ready to stop your application from running in the compute emulator, in the Eclipse toolbar, click the Reset Azure Emulator button, Reset Windows Azure emulator.

  1. In Eclipse’s Project Explorer, click MyAzureProject.

  2. In the Eclipse toolbar, click the Publish to Azure Cloud button, Publish to Windows Azure Cloud. If the Publish to Azure Cloud button is not enabled, ensure that MyAzureProject is selected in Eclipse’s Project Explorer, and ensure that Eclipse’s Project Explorer has focus as the current window. (As an alternative to using the Publish to Azure Cloud button, you can use the following menu choices: In Eclipse’s Project Explorer, right-click MyAzureProject, click Azure, and click Deploy to Azure Cloud.)

  3. In the Publish to Azure dialog:

    1. If there are no subscriptions to select in the Subscription list yet, follow these steps to import your subscription information:

      1. Click Import from PUBLISH-SETTINGS file.

      2. In the Import Subscription Information dialog, click Download PUBLISH-SETTINGS File. If you are not yet logged into your Azure account, you will be prompted to log in. Then you’ll be prompted to save an Azure publish settings file. Save it to your local machine.

      3. Still in the Import Subscription Information dialog, click the Browse button, select the publish settings file that you saved locally in the previous step, and then click Open. Your screen should look similar to the following.

        Import publish settings
      4. Click OK.

    2. For Subscription, select the subscription that you want use for your deployment.

    3. For Storage account, select the storage account that you want to use, or click New to create a new storage account.

    4. For Service name, select the cloud service that you want to use, or click New to create a new cloud service.

    5. For Target OS, select the version of the operating system that you want to use for your deployment.

    6. For Target environment, for purposes of this tutorial, select Staging. (When you’re ready to deploy to your production site, you’ll change this to Production.)

    7. [Optional] Ensure that Overwrite previous deployment is checked if you want your new deployment to automatically overwrite the previous deployment. When you enable this option, you will not experience "409 conflict" issues when publishing to the same location.

      Note that the Publish to Azure dialog contains a section for Remote Access. By default, Remote Access is not enabled and we will not enable it for this example. To enable Remote Access, you would enter a user name and password to use when remotely logging in. For more information about Remote Access, see Enabling Remote Access for Azure Deployments in Eclipse.

      Your Publish to Azure dialog will appear similar to the following:

      Publish Windows Azure Project dialog
  4. Click Publish to publish to the Staging environment.

    When prompted to perform a full build, click Yes. This may take several minutes for the first build.

    An Azure Activity Log will display in your Eclipse tabbed views section.

    Windows Azure Activity Log

    You can use this log, as well as the Console view, to see the progress of your deployment. An alternative is to log in to the Azure Management Portal, http://manage.windowsazure.com, and use the Cloud Services section to monitor the status.

  5. When your deployment is successfully deployed, the Azure Activity Log will show a status of Published. Click Published, as shown in the following image, and your browser will open an instance of your deployment.

    Windows Azure Activity Log - Published

Because this was a deployment to a staging environment, the DNS name will be of the form http://<guid>.cloudapp.net, and the URL will contain the DNS name plus a suffix for your application. For example, http://72d5eb5875234b7ca8c7f74c80a2a1f1.cloudapp.net/MyHelloWorld. (The MyHelloWorld portion is case-sensitive.) You can also see the DNS name if you click the deployment name in the Azure Platform Management Portal (within the Cloud Services portion of the management portal).

Although this walk-through was for a deployment to the staging environment, a deployment to production follows the same steps, except within the Publish to Azure dialog, select Production instead of Staging for the Target environment. A deployment to production results in a URL based on the DNS name of your choice, instead of a GUID as used for staging.

WarningWarning
At this point you have deployed your Azure application to the cloud. However, before proceeding, realize that a deployed application, even if it is not running, will continue to accrue billable time for your subscription. Therefore, it is extremely important that you delete unwanted deployments from your Azure subscription.

To delete your deployment within the Azure Toolkit for Eclipse with Java, ensure that MyAzureProject is selected in Eclipse’s Project Explorer, ensure the Eclipse Project Explorer has the current window focus, and then click the Unpublish button, Unpublish, in the Eclipse toolbar. (You could do the same operation by right-clicking MyAzureProject in Eclipse’s Project Explorer, clicking Azure and then clicking Undeploy from Azure Cloud.) This will display the Unpublish Azure Project dialog.

Unpublish Windows Azure Project dialog

Select the subscription and cloud service that contains your deployment, select the deployment that you want to delete, and then click Unpublish.

(An alternative to using the toolkit to delete the deployment is to use the Cloud Services section of the Azure Management Portal: Navigate to your deployment, select it, and then click the Delete button. This will stop, and then delete, the deployment. If you only want to stop the deployment and not delete it, click the Stop button instead of the Delete button, but as mentioned above, if you do not delete the deployment, billable charges will continue to accrue for your deployment even if it is stopped).

See Also

Show:
© 2014 Microsoft