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

Maven downloads dependencies and creates the project structure for you. It can take from a few seconds to a few minutes to complete. After confirming the prerequisites, open a console or command window and follow these steps:

  1. Create a new directory for your project.

  2. Change into the new directory and enter the following (all on one line):

    mvn archetype:generate -DarchetypeGroupId=com.lightbend.lagom -DarchetypeArtifactId=maven-archetype-lagom-java -DarchetypeVersion=1.3.6
  3. Maven prompts you for:

    • groupId — typically something like com.example.
    • artifactId — becomes the top-level folder name, for example, my-first-project.
    • version — the version for your project, press Enter to accept the default.
    • package — defaults to the same value as the groupId
  4. Enter Y to accept the values. Maven creates the project.

  5. Change into the top-level project folder and run it:

    mvn lagom:runAll

    The runAll command takes a bit of time. It starts Hello World microservices and registers them in a service directory. It also starts a Cassandra server and a web server.

  6. When you see the message, `Services started, ...`, 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.