Creating a Maven archetype for WildFly – Part 1

In this two-part tutorial we will learn how to create a Maven archetype for WildFly that you can use to speed up your project creation either from the command line or using an IDE

The first part of this tutorial will demonstrate how to create a basic archetype for a Web application which contains the needed dependencies in their place, and some useful plugins. This archetype will provide just the basic structure for your project. In the next tutorial we will add also test tooling configuration (Arquillian).

Creating a Maven archetype is straightforward process. An archetype in a nuthsell is a plugin, that contains the project prototype you wish to create and consists of:

  • An archetype descriptor (archetype-metadata.xml in directory: src/main/resources/META-INF/maven) which lists all the files that will be contained in the archetype
  • The resources that make up the archetype (in: src/main/resources/archetype-resources/)
  • The prototype for the pom.xml (in: src/main/resources/archetype-resources)
  • A pom.xml file which describes the archetype (pom.xml in the archetype’s root directory).

Here is the initial project structure for our archetype:

├── pom.xml
├── src
│   └── main
│       └── resources
│           ├── archetype-resources
│           │   ├── pom.xml
│           │   └── src
│           │       ├── main
│           │       │   ├── java
│           │       │   └── webapp
│           │       │       ├── index.html
│           │       │       └── WEB-INF
│           │       │           └── beans.xml
│           │       └── test
│           │           ├── java
│           │           └── resources
│           └── META-INF
│               └── maven
│                   └── archetype-metadata.xml

The first piece is the pom.xml which is located the root of the project, and contains the groupId,artifactId and version for our Archetype:

<project xmlns="" xmlns:xsi=""
  <name>Archetype Web Applications on WildFly</name>

Next, we need the actual pom.xml which will be generated in your project, when we use our archetype:

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
   <name>WildFly Webapp Archetype</name>


As you can see, the project contains in the first block a set of properties which will be replaced by your project’s actual configuration:


Then, we have included WildFly 12 BOM and a set of libraries you might need in your project. These libraries are commented for your convenience so you can uncomment just the ones you need. Finally, the wildfly-maven-plugin has been included as well so you can deploy/undeploy the project directly from Maven.

The other file we need is archetype-metadata.xml (in src/main/resources/META-INF/maven) which contains the list of files that need to be included in our Archetype. Since our Archetype merely adds an index.html welcome page, we will instruct it to include web pages from the src/main/webapp. In the next tutorial we’ll see how to generate sample Java classes and Test classes in our project.

<?xml version="1.0" encoding="UTF-8"?>
<archetype-descriptor xsi:schemaLocation="" 
                      name="JavaEE7 web application archetype"
    <fileSet filtered="true" encoding="UTF-8">

That’s all you need to create the archetype. We have included as well a WEB-INF/beans.xml file so that you have it already there, should you need CDI (remember you need to include its dependencies as well in pom.xml)

Now build install the archetype in your local repository with:

$ mvn clean install archetype:update-local-catalog

You will be informed that the archetype has been created by:

[INFO] Installing /home/jboss/maven-projects/webapp-wildfly/target/webapp-wildfly-12.jar to /home/jboss/.m2/repository/org/wildfly/webapp-wildfly/12/webapp-wildfly-12.jar
[INFO] Installing /home/jboss/maven-projects/webapp-wildfly/pom.xml to /home/jboss/.m2/repository/org/wildfly/webapp-wildfly/12/webapp-wildfly-12.pom
[INFO] --- maven-archetype-plugin:3.0.1:update-local-catalog (default-cli) @ webapp-wildfly ---
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.993 s
[INFO] Finished at: 2018-05-24T17:38:17+02:00
[INFO] ------------------------------------------------------------------------

Now let’s test it!

Since the archetype is in the local repository we can create a new Web application from it with:

$ mvn archetype:generate -Darchetype.interactive=false   --batch-mode -DarchetypeGroupId=org.wildfly -DarchetypeArtifactId=webapp-wildfly -DarchetypeVersion=12 -DgroupId=com.example -DartifactId=demoweb

Here is the project which has been created for you:

├── pom.xml
├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── example
│   │   └── webapp
│   │       ├── index.html
│   │       └── WEB-INF
│   │           └── beans.xml
│   └── test
│       ├── java
│       │   └── com
│       │       └── example
│       └── resources

Enter the folder of your application, and try to build and deploy it with:

$ mvn clean install wildfly:deploy

You can download this archetype and use it from here.

In the next tutorial (Creating a Maven archetype for WildFly – Part 2), we will learn how to create a more complex Archetype which contains some Java classes and a test class with Arquillian. Stay tuned!