Este conteúdo não está disponível no idioma selecionado.
Chapter 4. Develop MicroProfile applications for JBoss EAP
To get started with developing applications that use MicroProfile APIs, create a Maven project and define the required dependencies. Use the JBoss EAP MicroProfile Bill of Materials (BOM) to control the versions of runtime Maven dependencies in the application Project Object Model (POM).
After you create a Maven project, refer to the JBoss EAP XP Quickstarts for information about developing applications for specific MicroProfile APIs. For more information, see JBoss EAP XP Quickstarts.
4.1. Creating a Maven project with maven-archetype-webapp Copiar o linkLink copiado para a área de transferência!
Use the maven-archetype-webapp archetype to create a Maven project for building applications for JBoss EAP deployment. Maven provides different archetypes for creating projects based on templates specific to project types. The maven-archetype-webapp creates a project with the structure required to develop simple web-applications.
Prerequisites
- You have installed Maven. For more information, see Downloading Apache Maven.
Procedure
Set up a Maven project by using the
mvncommand. The command creates the directory structure for the project and thepom.xmlconfiguration file.Copy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
groupIDuniquely identifies the project.- 2
artifactIDis the name for the generatedjararchive.- 3
archetypeGroupIDis the unique ID formaven-archetype-webapp.- 4
archetypeArtifactIdis the artifact ID formaven-archetype-webapp.- 5
InteractiveModeinstructs Maven to use the supplied parameters rather than starting in interactive mode.
- Navigate to the generated directory.
-
Open the generated
pom.xmlconfiguration file in a text editor. Remove the content inside the
<project>section of thepom.xmlconfiguration file after the<name>helloworld Maven Webapp</name>line.Ensure that the file looks like this:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow The content was removed because it is not required for the application.
4.2. Defining properties in a Maven project Copiar o linkLink copiado para a área de transferência!
You can define properties in a Maven pom.xml configuration file as place holders for values. Define the value for JBoss EAP XP server as a property to use the value consistently in the configuration.
Prerequisites
You have initialized a Maven project.
For more information, see Creating a Maven project with
maven-archetype-webapp.
Procedure
Define a property
<version.bom.microprofile>as the JBoss EAP XP version on which you will deploy the configured application.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.3. Defining the repositories in a Maven project Copiar o linkLink copiado para a área de transferência!
Define the artifact and plug-in repositories in which Maven looks for artifacts and plug-ins to download.
Prerequisites
You have initialized a Maven project.
For more information, see Creating a Maven project with
maven-archetype-webapp.
Procedure
Define the artifacts repository.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Define the plug-ins repository.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.4. Importing the JBoss EAP MicroProfile BOM as dependency management in a Maven project Copiar o linkLink copiado para a área de transferência!
Import the JBoss EAP MicroProfile Bill of Materials (BOM) to control the versions of runtime Maven dependencies. When you specify a BOM in the <dependencyManagement> section, you do not need to individually specify the versions of the Maven dependencies defined in the provided scope.
Prerequisites
You have initialized a Maven project.
For more information, see Creating a Maven project with
maven-archetype-webapp.
Procedure
Add a property for the BOM version in the properties section of the
pom.xmlconfiguration file.<properties> ... <version.bom.microprofile>5.0.0.GA-redhat-00009</version.bom.microprofile> </properties><properties> ... <version.bom.microprofile>5.0.0.GA-redhat-00009</version.bom.microprofile> </properties>Copy to Clipboard Copied! Toggle word wrap Toggle overflow The value defined in the property
<version.bom.microprofile>is used as the value for the BOM version.Import the JBoss EAP BOMs dependency management.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
Optionally, you can import the JBoss EAP EE with Tools Bill to your project. For more information, see Importing the JBoss EAP BOMs as dependency management in a Maven project.
4.5. Importing the JBoss EAP BOMs as dependency management in a Maven project Copiar o linkLink copiado para a área de transferência!
You can optionally import the JBoss EAP EE With Tools Bill of materials (BOM). The JBoss EAP BOM provides supported JBoss EAP Java EE APIs plus additional JBoss EAP API JARs and client BOMs. You only need to import this BOM if your application requires Jakarta EE APIs in addition to the Microprofile APIs.
Prerequisites
You have initialized a Maven project.
For more information, see Creating a Maven project with
maven-archetype-webapp.
Procedure
Add a property for the BOM version in the properties section of the
pom.xmlconfiguration file.<properties> .... <version.bom.ee>8.0.0.GA-redhat-00009</version.bom.ee> </properties><properties> .... <version.bom.ee>8.0.0.GA-redhat-00009</version.bom.ee> </properties>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Import the JBoss EAP BOMs dependency management.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.6. Adding plug-in management in a Maven project Copiar o linkLink copiado para a área de transferência!
Add Maven plug-in management section to the pom.xml configuration file to get plug-ins required for Maven CLI commands.
Prerequisites
You have initialized a Maven project.
For more information, see Creating a Maven project with
maven-archetype-webapp.
Procedure
Define the versions for
wildfly-maven-pluginandmaven-war-plugin, in the<properties>section.<properties> ... <version.plugin.wildfly>4.2.1.Final</version.plugin.wildfly> <version.plugin.war>3.3.2</version.plugin.war> </properties><properties> ... <version.plugin.wildfly>4.2.1.Final</version.plugin.wildfly> <version.plugin.war>3.3.2</version.plugin.war> </properties>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add
<pluginManagement>in<build>section inside the<project>section.Copy to Clipboard Copied! Toggle word wrap Toggle overflow
4.7. Verifying a maven project Copiar o linkLink copiado para a área de transferência!
Verify that the Maven project you configured builds.
Prerequisites
You have defined Maven properties.
For more information, see Defining properties in a Maven project.
You have defined Maven repositories.
For more information, see Defining the repositories in a Maven project.
You have imported the JBoss EAP Bill of materials (BOMs) as dependency management.
For more information, see Importing the JBoss EAP MicroProfile BOM as dependency management in a Maven project.
You have added plug-in management.
For more information, see Adding plugin management in Maven project for a server hello world application.
Procedure
Install the Maven dependencies added in the
pom.xmllocally.mvn package
$ mvn packageCopy to Clipboard Copied! Toggle word wrap Toggle overflow You get an output similar to the following:
... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ...
... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow
For more information about developing applications for specific MicroProfile APIs, see JBoss EAP XP Quickstarts.