Using Lagom with Java and Maven

If you have the prerequisites installed and are familiar with Maven, create a Hello World project using the procedures on this page. Otherwise, see detailed instructions for help to set up the prerequisites and get started. Prerequisites for using Lagom with Maven include:

  • JDK 8
  • Maven 3.3 or higher

The Lightbend Tech Hub Project Starter makes it simple to create your first project. It invokes the Maven mvn archetype:generate command to create a Lagom Hello World project and compresses it in a zip file.

Download the project from Tech Hub

Follow these steps to download a project created from the template:

  1. Open the Tech Hub Project Starter.

  2. Click CREATE A PROJECT FOR ME.

    The browser downloads a compressed project.

Extract and run the project

After downloading the compressed file from Tech Hub, follow these steps:

  1. Extract the compressed file to a directory of your choice.

  2. In a shell, change into the top-level directory of the project, lagom-java-maven. For example, if you extracted the project into a directory named my-project:

    • In a macOS or Linux shell:
      cd my-project/lagom-java-maven
    • In a Windows shell:
      cd my-project\lagom-java-maven
  3. Start Maven and the Lagom development environment:

    mvn lagom:runAll

    It will take a bit of time to build and run the project. When finished, the console displays the message: Services started, ....

  4. Verify that the services are indeed up and running by invoking the hello service endpoint from any HTTP client, such as a browser: http://localhost:9000/api/hello/World

    The request returns the message Hello, World!.

Congratulations! You've created and run your first Lagom system. See the documentation to understand your new project.

You might find the Hello World template useful when starting a new project of your own. If you prefer to customize it more, see the manual instructions for generating a project from the Lagom Maven archetype.