- MicroProfile Introduction
MicroProfile is a collection of enterprise Java APIs that should feel familiar to Java EE developers. MicroProfile includes existing APIs such as JAX-RS, JSON-P and CDI, and adds additional APIs in areas such as configuration, metrics, fault tolerance and more.
Getting Started with Helidon MicroProfile
Helidon MP 1.4.12 supports MicroProfile 3.2. You can find the exact version of APIs supported on the Helidon Supported APIs wiki page.
Helidon provides a MicroProfile server implementation (io.helidon.microprofile.server) that encapsulates the Helidon WebServer. You can either instantiate the server directly as is done in the Helidon MP Quickstart example or use its built-in main as shown below.
Complete these tasks to get started with your MicroProfile application.
Maven Coordinates
The Managing Dependencies page describes how you should declare dependency management for Helidon applications. Then declare the following dependency in your project:
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile</artifactId>
</dependency>The above dependency adds all the features available in MicroProfile. If you want to start with a smaller core set of features then you can use the core bundle instead. This bundle includes the base feature in MicroProfile (such as JAX-RS, CDI, JSON-P/B, and Config) and leaves out some of the additional features such as Metrics and Tracing. You can add those dependencies individually if you choose.
<dependency>
<groupId>io.helidon.microprofile.bundles</groupId>
<artifactId>helidon-microprofile-core</artifactId>
</dependency>Project files
Create a JAX-RS Resource class with at least one resource method.
@Path("/")
@RequestScoped
public class HelloWorldResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String message() {
return "Hello World";
}
}And create a JAX-RS application.
@ApplicationScoped
@ApplicationPath("/")
public class HelloWorldApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return Set.of(
HelloWorldResource.class
);
}
}Add beans.xml in src/main/resources/META-INF so the CDI implementation can pick up your classes.
<?xml version="1.0" encoding="UTF-8"?>
<beans/>As a last step, add a main method to your application (or a dedicated Main class) to start everything up.
public static void main(String[] args) {
io.helidon.microprofile.server.Main.main(args);
}Run the main class. The server will start on port 7001 and serve your resources.
Adding Jandex
Jandex is an indexing tool for Weld (the CDI implementation used by Helidon) that helps speed up the boot time of an application.
To use Jandex, configure a Maven plugin that adds the index to your JAR file and a dependency on Jandex.
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jandex</artifactId>
<version>2.0.4.Final</version>
</dependency><build>
<plugins>
<plugin>
<groupId>org.jboss.jandex</groupId>
<artifactId>jandex-maven-plugin</artifactId>
<version>1.0.5</version>
<executions>
<execution>
<id>make-index</id>
<goals>
<goal>jandex</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>