Using the CLI you can create a new Micronaut application in either Groovy, Java or Kotlin (the default is Java).

    The following command creates a new “Hello World” server application in Java with a Gradle build:

    1. $ ./gradlew run
    2. > Task :run
    3. [main] INFO io.micronaut.runtime.Micronaut - Startup completed in 972ms. Server Running: http://localhost:28933

    If you have created a Maven based project, use ./mvnw mn:run instead.

    By default the Micronaut HTTP server is configured to run on port 8080. See the section in the user guide for more options.

    1. import io.micronaut.http.MediaType
    2. import io.micronaut.http.annotation.Controller
    3. @Controller('/hello') (1)
    4. class HelloController {
    5. @Get(produces = MediaType.TEXT_PLAIN) (2)
    6. 'Hello World' (3)
    7. }

    If you are using Java, place the previous file in src/main/java/hello/world.
    If you are using Groovy, place the previous file in src/main/groovy/hello/world.
    If you are using Kotlin, place the previous file in src/main/kotlin/hello/world.

    If you start the application and send a request to the /hello URI then the text “Hello World” is returned:

    1. $ curl http://localhost:8080/hello