mp.introduction.microprofile.adoc Maven / Gradle / Ivy
///////////////////////////////////////////////////////////////////////////////
Copyright (c) 2019, 2024 Oracle and/or its affiliates.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
///////////////////////////////////////////////////////////////////////////////
= Helidon MicroProfile
:description: getting started with Helidon Microprofile
:keywords: helidon, microprofile, micro-profile
:rootdir: {docdir}/../..
include::{rootdir}/includes/mp.adoc[]
Complete these tasks to get started with your MicroProfile application.
== Getting Started with Helidon MicroProfile
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 xref:../guides/quickstart.adoc[Helidon MP Quickstart example]
or use its built-in `main` as shown below.
=== Maven Coordinates
The xref:../../about/managing-dependencies.adoc[Managing Dependencies] page describes
how you should declare dependency management for Helidon applications.
Then declare the following dependency in your project:
[source,xml]
.Maven Dependency for full MicroProfile
----
io.helidon.microprofile.bundles
helidon-microprofile
----
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.
[source,xml]
.Maven Dependency for MicroProfile core features only
----
io.helidon.microprofile.bundles
helidon-microprofile-core
----
=== Project files
Create a JAX-RS Resource class with at least one resource method.
[source,java]
.Sample JAX-RS Resource Class
----
include::{sourcedir}/mp/introduction/MicroprofileSnippets.java[tag=snippet_1, indent=0]
----
And create a JAX-RS application.
[source,java]
.Sample JAX-RS Application
----
include::{sourcedir}/mp/introduction/MicroprofileSnippets.java[tag=snippet_2, indent=0]
----
Add `beans.xml` in `src/main/resources/META-INF` so
the CDI implementation can pick up your classes.
[source,xml]
.beans.xml
----
----
As a last step, add a main method to your application (or a dedicated Main class)
to start everything up.
[source,java]
.Sample JAX-RS Application
----
include::{sourcedir}/mp/introduction/MicroprofileSnippets.java[tag=snippet_3, indent=0]
----
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.
[source,xml]
.jandex dependency
----
io.smallrye
jandex
{version.plugin.jandex}
----
[source,xml]
.jandex plugin configuration
----
io.smallrye
jandex-maven-plugin
3.1.2
make-index
jandex
process-classes
----
© 2015 - 2025 Weber Informatics LLC | Privacy Policy