PageRenderTime 24ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/articles/azure-toolkit-for-eclipse-creating-a-hello-world-application.md

https://gitlab.com/yeah568/azure-content
Markdown | 196 lines | 146 code | 50 blank | 0 comment | 0 complexity | 563601062d74b950604b341e3d502bb5 MD5 | raw file
  1. <properties
  2. pageTitle="Create a Hello World Cloud Service for Azure in Eclipse"
  3. description="Learn how to create a simple Hello World application using the Azure Toolkit for Eclipse."
  4. services=""
  5. documentationCenter="java"
  6. authors="rmcmurray"
  7. manager="wpickett"
  8. editor=""/>
  9. <tags
  10. ms.service="multiple"
  11. ms.workload="na"
  12. ms.tgt_pltfrm="multiple"
  13. ms.devlang="Java"
  14. ms.topic="article"
  15. ms.date="06/24/2016"
  16. ms.author="robmcm"/>
  17. <!-- Legacy MSDN URL = https://msdn.microsoft.com/library/azure/hh690944.aspx -->
  18. # Create a Hello World Cloud Service for Azure in Eclipse #
  19. 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.
  20. The application will look similar to the following:
  21. ![][ic600360]
  22. ## Prerequisites ##
  23. * A Java Developer Kit (JDK), v 1.7 or later.
  24. * Eclipse IDE for Java EE Developers, Indigo or later. This can be downloaded from <http://www.eclipse.org/downloads/>.
  25. * A distribution of a Java-based web server or application server, such as Apache Tomcat, GlassFish, JBoss Application Server, Jetty, or IBM® WebSphere® Application Server Liberty Core.
  26. * An Azure subscription, which can be acquired from <http://azure.microsoft.com/pricing/purchase-options/>.
  27. * The Azure Toolkit for Eclipse. For more information, see [Installing the Azure Toolkit for Eclipse][].
  28. ## To create a Hello World application ##
  29. First, we'll start off with creating a Java project.
  30. * Start Eclipse, and 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**.)
  31. * 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:
  32. ![][ic589576]
  33. * Click **Finish**.
  34. * Within Eclipse's Project Explorer view, expand **MyHelloWorld**. Right-click **WebContent**, click **New**, and then click **JSP File**.
  35. * In the **New JSP File** dialog, name the file **index.jsp**. Keep the parent folder as **MyHelloWorld/WebContent**, as shown in the following:
  36. ![][ic659262]
  37. * In the **Select JSP Template** dialog, for purposes of this tutorial select **New JSP File (html)** and click **Finish**.
  38. * When the index.jsp file opens in Eclipse, add in text to dynamically display **Hello World!** within the existing `<body>` element. Your updated `<body>` content should appear as the following:
  39. ```
  40. <body>
  41. <b><% out.println("Hello World!"); %></b>
  42. </body>
  43. ```
  44. * Save index.jsp.
  45. ## To deploy your application to Azure, the quick and simple way ##
  46. As soon as you have a Java web application ready to test, you can use the following shortcut to try it out directly on the Azure cloud.
  47. 1. In Eclipse's Project Explorer, click **MyHelloWorld**.
  48. 1. In the Eclipse toolbar, click the **Publish** drop down button and then click **Publish As Azure Cloud Service**
  49. ![][publishDropdownButton]
  50. 1. If you are publishing this application to Azure for the first time and you have not created an Azure deployment project for this application before, an Azure deployment project be created for you automatically. You should see the following prompt, which also lists the JDK package and application server that will be automatically deployed to run your application.
  51. ![][ic789598]
  52. This shortcut approach enables a quick and easy way to test your application in Azure without having to configure a specific server or JDK that is different from the defaults. If you are satisfied with the defaults, you can click **OK** to continue with the following steps.
  53. However, if you want to change the JDK or application server to use for your application, you can do that later by editing the Azure deployment project that was automatically created for you, or you can click **Cancel** now and read the **About Azure deployment projects section** of this tutorial.
  54. 1. In the **Publish to Azure** dialog:
  55. 1. If there are no subscriptions to select in the **Subscription** list yet, follow these steps to import your subscription information:
  56. 1. Click **Import from PUBLISH-SETTINGS file**.
  57. 1. 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.
  58. 1. 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:
  59. ![][ic644267]
  60. 1. Click **OK**.
  61. 1. For **Subscription**, select the subscription that you want use for your deployment.
  62. 1. For **Storage account**, select the storage account that you want to use, or click **New** to create a new storage account.
  63. 1. For **Service name**, select the cloud service that you want to use, or click **New** to create a new cloud service.
  64. 1. For **Target OS**, select the version of the operating system that you want to use for your deployment.
  65. 1. 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**.)
  66. 1. 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.
  67. 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][].
  68. Your **Publish to Azure** dialog will appear similar to the following:
  69. ![][ic719488]
  70. 1. Click **Publish** to publish to the Staging environment.
  71. When prompted to perform a full build, click **Yes**. This may take several minutes for the first build.
  72. An **Azure Activity Log** will display in your Eclipse tabbed views section.
  73. ![][ic719489]
  74. 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][], and use the **Cloud Services** section to monitor the status.
  75. 1. 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.
  76. ![][ic719490]
  77. Because this was a deployment to a staging environment, the DNS name will be of the form http://&lt;*guid*&gt;.cloudapp.net, and the URL will contain the DNS name plus a suffix for your application. For example, http://447564652c20426f6220526f636b7321.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).
  78. 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.
  79. >[AZURE.WARNING] 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.
  80. ## About Azure deployment projects ##
  81. In order to deploy one or more Java applications to Azure, an Azure Deployment Project is needed. It plays the role of the "package" that your applications need to be wrapped into in order to be published on Azure.
  82. Besides the information about your applications, an Azure deployment project also contains information about other key components of your deployment, most importantly: the application server container to run your web app in, and the Java runtime to run it on. Azure supports a large selection of Java runtimes and Java application servers you can choose from.
  83. Although the example used here is greatly simplified for educational purposes, an Azure deployment project can also contain other important configuration information that enables you to create almost arbitrarily complex, scalable, highly available, multi-tier cloud services with your applications. You can enable **session affinity ("sticky sessions")**, **fast caching**, **remote debugging**, **SSL offloading**, **firewall/port routing**, **remote access**, and a number of other powerful capabilities.
  84. If you've completed the previous section of this tutorial ("To deploy your application to Azure, the quick and simple way"), you will now see a new Azure deployment project in the Project Explorer generated for you automatically and named "**MyHelloWorld_onAzure**".
  85. You could have also started this tutorial by first creating a blank Azure deployment project yourself and then adding your application(s) to it. It is a longer process, but giving you more control over the initial configuration from the beginning.
  86. To create a new Azure deployment project from scratch, click the **New Azure Deployment Project** button ![][ic710876].
  87. Regardless of whether you are working with an already existing Azure deployment project, or creating one from scratch, you are able to change its configuration settings and components, such as the JDK or the application server, equally easily at any time.
  88. To change the JDK, or the application server, or the application list in an existing Azure deployment project:
  89. 1. Expand the project node (e.g. **MyHelloWorld_onAzure**) in the Project Explorer
  90. 2. Right-click **WorkerRole1**
  91. 3. Expand the **Azure** submenu in the context menu
  92. 4. Click **Server Configuration**
  93. Regardless of whether you started these server configuration steps by editing an existing Azure deployment project as shown above, or creating a new one from scratch, you will see the same type of dialogs allowing you to configure your JDK, server and application components. To learn more how to change the settings in those dialogs, for example to change the JDK, the application server and add or remove applications in a deployment, see the [Server configuration properties][] article.
  94. ## Windows only: To deploy your application to the compute emulator ##
  95. >[AZURE.NOTE] The Azure emulator is only available on Windows. Skip this section if you are using an operating system other than Windows.
  96. If you have created a new Azure deployment project following the steps described earlier, i.e. implicitly, by publishing your application to Azure, the JDK and application servers have been configured for the cloud, but not for local emulation. To prepare your project for testing in the local emulator, follow these steps:
  97. 1. In Eclipse's Project Explorer, click **MyHelloWorld_onAzure**.
  98. 1. Right-click on **WorkerRole1**.
  99. 1. Expand the **Azure** submenu in the context menu.
  100. 1. Click **Server Configuration**.
  101. 1. On the **JDK** tab, check if the toolkit has pre-configured a default local JDK for you. If not, or if you want to change the assumed defaults, ensure that the **Use the JDK from this file path for testing locally** checkbox is checked and the JDK installation location that you want to use is specified. If you want to change it, click the **Browse** button and using the browse control, select the directory location of the JDK to use.
  102. 1. Click the **Server** tab.
  103. 1. In the **Local server path** text box at the bottom of the dialog box, enter the path of a locally-installed server that matches the type and major version number of the server selected at the top of the dialog box, under the **Deploy a server of this type** checkbox. If you want to use a different type or major version of the application server, change the selection under that checkbox first.
  104. 1. Click **OK**.
  105. 1. In the Eclipse toolbar, click the **Run in Azure Emulator** button, ![][ic710879]. If the **Run in Azure Emulator** button is not enabled, ensure that **MyHelloWorld_onAzure** 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**.
  106. >[AZURE.IMPORTANT] 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.
  107. 1. 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.
  108. 1. 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:
  109. ![][ic589579]
  110. When you are ready to stop your application from running in the compute emulator, in the Eclipse toolbar, click the **Reset Azure Emulator** button, ![][ic710880].
  111. ## To delete your deployment ##
  112. To delete your deployment within the Azure Toolkit for Eclipse, ensure that **MyHelloWorld_onAzure** is selected in Eclipse's Project Explorer, ensure the Eclipse Project Explorer has the current window focus, and then click the **Unpublish** button, ![][ic710883], in the Eclipse toolbar. (You could do the same operation by right-clicking **MyHelloWorld_onAzure** in Eclipse's Project Explorer, clicking **Azure** and then clicking **Undeploy from Azure Cloud**.) This will display the **Unpublish Azure Project** dialog.
  113. ![][ic719491]
  114. Select the subscription and cloud service that contains your deployment, select the deployment that you want to delete, and then click **Unpublish**.
  115. (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).
  116. ## See Also ##
  117. [Azure Toolkit for Eclipse][]
  118. [Installing the Azure Toolkit for Eclipse][]
  119. [What's New in the Azure Toolkit for Eclipse][]
  120. For more information about using Azure with Java, see the [Azure Java Developer Center][].
  121. <!-- URL List -->
  122. [Azure Java Developer Center]: http://go.microsoft.com/fwlink/?LinkID=699547
  123. [Azure Management Portal]: http://go.microsoft.com/fwlink/?LinkID=512959
  124. [Azure Role Properties]: http://go.microsoft.com/fwlink/?LinkID=699525
  125. [Azure Toolkit for Eclipse]: http://go.microsoft.com/fwlink/?LinkID=699529
  126. [Enabling Remote Access for Azure Deployments in Eclipse]: http://go.microsoft.com/fwlink/?LinkID=699538
  127. [Installing the Azure Toolkit for Eclipse]: http://go.microsoft.com/fwlink/?LinkId=699546
  128. [Server configuration properties]: http://go.microsoft.com/fwlink/?LinkID=699525#server_configuration_properties
  129. [What's New in the Azure Toolkit for Eclipse]: http://go.microsoft.com/fwlink/?LinkID=699552
  130. <!-- IMG List -->
  131. [ic589576]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic589576.png
  132. [ic589579]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic589579.png
  133. [ic600360]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic600360.png
  134. [ic644267]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic644267.png
  135. [ic659262]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic659262.png
  136. [ic710876]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic710876.png
  137. [ic710879]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic710879.png
  138. [ic710880]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic710880.png
  139. [ic710882]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic710882.png
  140. [ic710883]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic710883.png
  141. [ic719488]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic719488.png
  142. [ic719489]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic719489.png
  143. [ic719490]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic719490.png
  144. [ic719491]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic719491.png
  145. [ic789598]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/ic789598.png
  146. [publishDropdownButton]: ./media/azure-toolkit-for-eclipse-creating-a-hello-world-application/publishDropdownButton.png