Exercise: Create a Simple Java Web App

Completed

Create a simple Java web app

In this exercise, you create a minimal Java web application that serves a simple "Hello, World!" message using Java 17 and Maven. This application runs on a built-in HTTP server and can be deployed to Azure App Service.

You have two options to proceed. Select the relevant tab based on your preference.

Clone the project repo

Within your directory of choice, use the following command to clone the sample project repo:

git clone https://github.com/MicrosoftDocs/hello-java-azure.git

Now, use the following command to navigate to inside the cloned project repo:

cd hello-java-azure

Run your application locally

You can run your application by using the following steps:

  1. Compile and package the Java project. Use the following command to compile the code:

    mvn clean package
    
  2. Run the application. Use the following command to compile the code:

    java -jar target/hello-java-azure-1.0-SNAPSHOT.jar
    

    You should see the following output, which indicates that the server started:

    Server started on http://localhost:8080/
    
  3. Test your application. Open your web browser and go to: http://localhost:8080/.

    You should see the message: Hello, World! on your screen.