In this tutorial we will learn how to configure Maven Project Object Module (pom.xml) so that you can easily build and deploy your applications running on WildFly. In order to do that we will use the following BOM which is available in Maven Central Repository: http://central.maven.org/maven2/org/wildfly/bom/wildfly-javaee7-with-tools/

What is a BOM ?

A BOM is also called Bill Of Materials - it bundles several dependencies to assure that the versions will work together. JBoss has boms for many of it's projects, including Arquillian and the WildFly itself.

Here is the BOM for WildFly 10:

<properties>
       	 <version.jboss.bom>10.0.0.Final</version.jboss.bom>
</properties>

 <dependencyManagement>
        <dependencies>         
            <dependency>
                <groupId>org.wildfly.bom</groupId>
                <artifactId>wildfly-javaee7-with-tools</artifactId>
                <version>${version.jboss.bom}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
</dependencyManagement>

Now, with the BOM in place, all you have to do is including the dependencies which are required for your project. You don't need to specify the version as it will be retrieved from the BOM. For example, if you need to include the EJB 3.2 in your project:

<dependency>
      <groupId>org.jboss.spec.javax.ejb</groupId>
      <artifactId>jboss-ejb-api_3.2_spec</artifactId>
      <scope>provided</scope>
</dependency>

Here's the full pom.xml I have used to compile, package and deploy a (EJB+CDI+JPA) Java EE 7 application on WildFly 10:

<?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/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
   <groupId>com.mastertheboss</groupId>
   <artifactId>javaee7example</artifactId>
   <version>1.0-SNAPSHOT</version>
   <packaging>war</packaging>
   <name>Java EE 6 webapp project</name>
   <description>A starter Java EE 7 webapp project for use on WildFly 10</description>
   <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
      <version.jboss.bom>10.0.0.Final</version.jboss.bom>
      <maven.build.timestamp.format>yyyyMMdd'T'HHmmss</maven.build.timestamp.format>
      <version.wildfly.maven.plugin>1.0.2.Final</version.wildfly.maven.plugin>
   </properties>
   <dependencyManagement>
      <dependencies>
         <dependency>
            <groupId>org.wildfly.bom</groupId>
            <artifactId>wildfly-javaee7-with-tools</artifactId>
            <version>${version.jboss.bom}</version>
            <type>pom</type>
            <scope>import</scope>
         </dependency>
      </dependencies>
   </dependencyManagement>
   <dependencies>
      <dependency>
         <groupId>javax.enterprise</groupId>
         <artifactId>cdi-api</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.jboss.spec.javax.annotation</groupId>
         <artifactId>jboss-annotations-api_1.2_spec</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.jboss.spec.javax.ws.rs</groupId>
         <artifactId>jboss-jaxrs-api_2.0_spec</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.hibernate.javax.persistence</groupId>
         <artifactId>hibernate-jpa-2.1-api</artifactId>
         <scope>provided</scope>
      </dependency>
      <dependency>
         <groupId>org.jboss.spec.javax.ejb</groupId>
         <artifactId>jboss-ejb-api_3.2_spec</artifactId>
         <scope>provided</scope>
      </dependency>
   </dependencies>
   <build>
      <finalName>${project.artifactId}</finalName>
      <plugins>
         <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
               <source>1.6</source>
               <target>1.6</target>
            </configuration>
         </plugin>
         <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
               <!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
               <failOnMissingWebXml>false</failOnMissingWebXml>
            </configuration>
         </plugin>
         <plugin>
            <groupId>org.wildfly.plugins</groupId>
            <artifactId>wildfly-maven-plugin</artifactId>
            <version>${version.wildfly.maven.plugin}</version>
         </plugin>
      </plugins>
   </build>
   <profiles>
      <profile>
         <id>default</id>
         <activation>
            <activeByDefault>true</activeByDefault>
         </activation>
         <build>
            <plugins>
               <plugin>
                  <artifactId>maven-surefire-plugin</artifactId>
                  <version>2.4.3</version>
                  <configuration>
                     <skip>true</skip>
                  </configuration>
               </plugin>
            </plugins>
         </build>
      </profile>
   </profiles>
</project>

Notice also the Maven WildFly plugin which can be used to manage your applications from the Maven shell. Just build and deploy your applications with:

mvn install wildfly:deploy

wildfly 10 bookGet your hands now on WildFly 10 with WildFly 10 Administration Guide!

This book covers all details on administration and management aspect of this new exciting version of the application server. Focusing exclusively on the management instruments of the application server, the book takes you through all of the latest architectural and performance changes. You’ll progress from basic server configuration to more advanced techniques for clustering, JDBC connectivity, logging, and much more.

 

0
0
0
s2smodern

Related articles available on mastertheboss.com

Wildfly 8 introduction

JBoss AS has a new name: as you probably know future versions of

Configuring Eclipse to use WildFly

How do I integrate WildFly with Eclipse? This tutorial shows how

Running WildFly with JDK 8

The JDK 1.8 early access is available for download at Oracle's si

Patching WildFly application server

The final version of WildFly 8.1.0 has been released and it conta

Configuring WildFly Batch Job Repository

WildFly ships with a subsystem named batch which is the administr

Monitoring WildFly using VisualVM

This short tutorial shows how you can connect to WildFly 8 using