Micronaut-core: Creating first Micronaut sample with maven dependencies

Created on 26 Sep 2018  路  2Comments  路  Source: micronaut-projects/micronaut-core

I followed this (http://guides.micronaut.io/creating-your-first-micronaut-app/guide/index.html) guide but instead of generate a Gradle project I created a new project with maven dependencies.

In that way I only have two classes: Application.java and HelloController.java.
My purpose was to simply run Application.java in Intellij's IDE.

Expected Behaviour

What I expected was the creation of a random port localhost which I would be able to invoke with, for example, postman's application.

Actual Behaviour

What really happens is that when I run the class the following message appears:

_"io.micronaut.runtime.Micronaut start
INFO: No embedded container found. Running as CLI application"_.

Environment Information

  • Operating System: Microsoft Windows 10 Enterprise (v. 10.0.16299)
  • Micronaut Version: 1.0-SNAPSHOT
  • JDK Version: started with 10 but currently 1.8.0_181 (_downgraded to check if would solve the issue_)
  • IDE: Intellij Idea (_with Annotation Processing enabled_)

Code


HelloController.java

package example.micronaut;

import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.Controller;
import io.micronaut.http.annotation.Get;
import io.micronaut.http.annotation.Produces;

@Controller("/hello") 
public class HelloController {
    @Get("/") 
    @Produces(MediaType.TEXT_PLAIN) 
    public String index() {
        return "Hello World"; 
    }
}

Application.java

package example.micronaut;

import io.micronaut.runtime.Micronaut;

  public class Application {
    public static void main(String[] args) {
        Micronaut.run(Application.class);
    }
 }

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 
         4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.microservice</groupId>
    <artifactId>example-micronaut</artifactId>
    <version>1.0-SNAPSHOT</version>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>example.micronaut.Application</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>

        <!-- JAVA 9+ and LOG dependencies -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-jdk14</artifactId>
            <version>1.7.25</version>
        </dependency>
        <dependency>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
            <version>1.3.2</version>
        </dependency>

        <!-- Project dependencies -->
        <dependency>
            <groupId>io.micronaut</groupId>
            <artifactId>runtime</artifactId>
            <version>1.0.0.M4</version>
        </dependency>
        <dependency>
            <groupId>io.micronaut</groupId>
            <artifactId>http-client</artifactId>
            <version>1.0.0.M4</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>

    </dependencies>

</project>
cannot reproduce

Most helpful comment

@mOo7King On a Windows 10 machine, I took the following steps using Micronaut 1.0.0.M4 (git bash shell):

mn create-app test --build maven
cd test
./mvnw compile
./mvnw exec:exec

The application started successfully.

The pom.xml file you have there will definitely not work as there is more configuration that is required.

All 2 comments

@mOo7King On a Windows 10 machine, I took the following steps using Micronaut 1.0.0.M4 (git bash shell):

mn create-app test --build maven
cd test
./mvnw compile
./mvnw exec:exec

The application started successfully.

The pom.xml file you have there will definitely not work as there is more configuration that is required.

@jameskleeh Thanks for helping. It worked for me.

Was this page helpful?
0 / 5 - 0 ratings