Chapter 1. Creating a Maven project for a hello world application A Maven project contains a pom.xml configuration file and has the directory structure required for creating an application. You can configure the pom.xml configuration file to add dependencies for your application. To create a Maven project for a hello world application, follow these procedures: Creating a Maven project with maven-archetype-webapp Defining properties in a Maven project Defining the repositories in a Maven project Importing the JBoss EAP BOMs as dependency management in a Maven project Adding plug-in management in a Maven project Verifying a maven project 1.1. Creating a Maven project with maven-archetype-webapp 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 mvn command. The command creates the directory structure for the project and the pom.xml configuration file. 1 groupID uniquely identifies the project. 2 artifactID is the name for the generated jar archive. 3 The groupID of maven-archetype-webapp . 4 The artifactID of maven-archetype-webapp . 5 Tell Maven to use the supplied parameters rather than starting interactive mode. Navigate to the generated directory. Open the generated pom.xml configuration file in a text editor. Remove the content inside the <project> section of pom.xml configuration file after the <name>helloworld Maven Webapp</name> line. Ensure that the file looks like this: <?xml version="1.0" encoding="UTF-8"?> <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>org.jboss.as.quickstarts</groupId> <artifactId>helloworld</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>helloworld Maven Webapp</name> </project> The content was removed because it is not required for the application. steps Defining properties in Maven project for a JBoss EAP hello world application . 1.2. Defining properties in a Maven project You can define properties in a Maven pom.xml configuration file as place holders for values. Define the value for JBoss EAP server as a property to use the value consistently in the configuration. Prerequisites You have initialized a Maven project. For more informartion, see Initializing a Maven project for a JBoss EAP hello world application . Procedure Define a property <version.server> as the JBoss EAP version on which you will deploy the configured application. <project> ... <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <version.server>8.0.0.GA-redhat-00009</version.server> </properties> </project> steps Defining the repositories in a Maven project . 1.3. Defining the repositories in a Maven project 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 informartion, see Initializing a Maven project for a JBoss EAP hello world application . Procedure Define the artifacts repository. <project> ... <repositories> <repository> 1 <id>jboss-public-maven-repository</id> <name>JBoss Public Maven Repository</name> <url>https://repository.jboss.org/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> <layout>default</layout> </repository> <repository> 2 <id>redhat-ga-maven-repository</id> <name>Red Hat GA Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> <layout>default</layout> </repository> </repositories> </project> 1 The Red Hat GA Maven repository provides all the productized JBoss EAP and other Red Hat artifacts. 2 The JBoss Public Maven Repository provides artifacts such as WildFly Maven plug-ins Define the plug-ins repository. <project> ... <pluginRepositories> <pluginRepository> <id>jboss-public-maven-repository</id> <name>JBoss Public Maven Repository</name> <url>https://repository.jboss.org/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>redhat-ga-maven-repository</id> <name>Red Hat GA Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project> steps Importing the JBoss EAP BOMs dependency management in Maven project . 1.4. Importing the JBoss EAP BOMs as dependency management in a Maven project Import the JBoss EAP EE With Tools 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 informartion, see Initializing a Maven project for a JBoss EAP hello world application . Procedure Add a property for the BOM version in the properties section of the pom.xml configuration file. <properties> .... <version.bom.ee>USD{version.server}</version.bom.ee> </properties> The value defined in the property <version.server> is used as the value for BOM version. Import the JBoss EAP BOMs dependency management. <project> ... <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.bom</groupId> 1 <artifactId>jboss-eap-ee-with-tools</artifactId> 2 <version>USD{version.bom.ee}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project> 1 GroupID of the JBoss EAP-provided BOM. 2 ArtifactID of the JBoss EAP-provided BOM that provides supported JBoss EAP Java EE APIs plus additional JBoss EAP API JARs and client BOMs, and development tools such as Arquillian. steps Adding plug-in management in a Maven project 1.5. Adding plug-in management in a Maven project 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 informartion, see Initializing a Maven project for a JBoss EAP hello world application . Procedure Define the versions for wildfly-maven-plugin and maven-war-plugin , in the <properties> section. <properties> ... <version.plugin.wildfly>4.1.1.Final</version.plugin.wildfly> <version.plugin.war>3.3.2</version.plugin.war> </properties> Add <pluginManagement> in <build> section inside the <project> section. <project> ... <build> <pluginManagement> <plugins> <plugin> 1 <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>USD{version.plugin.wildfly}</version> </plugin> <plugin> 2 <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>USD{version.plugin.war}</version> </plugin> </plugins> </pluginManagement> </build> </project> 1 You can use the wildfly-maven-plugin to deploy an application to JBoss EAP using the wildfly:deploy command. 2 You need to manage the war plugin version to ensure compatibility with JDK17+. steps Verifying a maven project 1.6. Verifying a maven project 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 BOMs 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.xml locally. You get an output similar to the following: steps Creating a hello world servlet

Commands:
mvn archetype:generate -DgroupId=org.jboss.as.quickstarts \ 1 -DartifactId=helloworld \ 2 -DarchetypeGroupId=org.apache.maven.archetypes \ 3 -DarchetypeArtifactId=maven-archetype-webapp \ 4 -DinteractiveMode=false 5
cd helloworld
<?xml version="1.0" encoding="UTF-8"?> <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>org.jboss.as.quickstarts</groupId> <artifactId>helloworld</artifactId> <version>1.0-SNAPSHOT</version> <packaging>war</packaging> <name>helloworld Maven Webapp</name> </project>
<project> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> <version.server>8.0.0.GA-redhat-00009</version.server> </properties> </project>
<project> <repositories> <repository> 1 <id>jboss-public-maven-repository</id> <name>JBoss Public Maven Repository</name> <url>https://repository.jboss.org/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> <layout>default</layout> </repository> <repository> 2 <id>redhat-ga-maven-repository</id> <name>Red Hat GA Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> <layout>default</layout> </repository> </repositories> </project>
<project> <pluginRepositories> <pluginRepository> <id>jboss-public-maven-repository</id> <name>JBoss Public Maven Repository</name> <url>https://repository.jboss.org/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>redhat-ga-maven-repository</id> <name>Red Hat GA Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </project>
<properties> . <version.bom.ee>USD{version.server}</version.bom.ee> </properties>
<project> <dependencyManagement> <dependencies> <dependency> <groupId>org.jboss.bom</groupId> 1 <artifactId>jboss-eap-ee-with-tools</artifactId> 2 <version>USD{version.bom.ee}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>
<properties> <version.plugin.wildfly>4.1.1.Final</version.plugin.wildfly> <version.plugin.war>3.3.2</version.plugin.war> </properties>
<project> <build> <pluginManagement> <plugins> <plugin> 1 <groupId>org.wildfly.plugins</groupId> <artifactId>wildfly-maven-plugin</artifactId> <version>USD{version.plugin.wildfly}</version> </plugin> <plugin> 2 <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>USD{version.plugin.war}</version> </plugin> </plugins> </pluginManagement> </build> </project>
mvn package
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------