Build Java EE Projects with Forge 3

JBoss Forge ships now with the 3.x release which brings several enhancements to the project creator engine. Besides it, the release 3.x has changed the option names syntax a bit, switching to a dashed and lower-cased structure. Let's see how we can quickly create a project to be deployed on WildFly 10.

Starting Forge 3

Forge downloads are available at: https://forge.jboss.org/download

Pickup the latest stable version and start the forge tool:

$ bin/forge

You can even skip the installation if you have JBoss Developer Studio which already ships with Forge Console. Just switch the view to Forge Console and you can start using Forge!

JBoss Forge 3 tutorial

Creating a simple Java EE Project with Forge

Let's start building up a new project named "demo-forge" which uses the JAVA EE 7 stack, therefore its target will be WildFly:

project-new  --named demo-forge --type war --stack JAVA_EE_7

What is really cool if you are using JBoss Developer Studio is that the project will be automatically created in your Workspace so no need to search and import it:

JBoss Forge 3 tutorial

Now let's create one Model object which will be eventually scaffolded:

jpa-new-entity --named Customer

jpa-new-field --named name --not-nullable
jpa-new-field --named surname --not-nullable
jpa-new-field --named email --not-nullable

As you can see, we have created the Customer Entity class and included a basic NotNull constraint on the top of it. If we want, we can create more complex constraint such as Regular Expression patterns as follows:

constraint-add --on-property email --constraint Pattern --regexp ^(.+)@(.+)$

Done with the model, we will now create the Faces layer through the scaffold-generate command, specifying the provider (Faces) and the Web context root:

scaffold-generate --targets org.demo.forge.model.Customer --web-root demo-forge --provider Faces

Please note that Forge uses lots of defaults to simplify your project creation. In our case, as we have omitted the base package name in the project creation, the root package org.[project.name] has been usedDone with the project, it's time to build it, which will trigger the maven install command:@SHELLbuild

Deploying the project to WildFly can be easily achieved by adding to your pom.xml the Maven's WildFly plugin

<plugin>
    <groupId>org.wildfly.plugins</groupId>
    <artifactId>wildfly-maven-plugin</artifactId>
    <version>1.0.2.Final</version>
    <configuration>
        <filename>${project.build.finalName}.war</filename>
    </configuration>
</plugin>

Otherwise, you can do it directly from Forge, but you have to install a couple of adds-on first:

addon-install-from-git --url https://github.com/forge/as-addon  --coordinate org.jboss.forge.addon:as
addon-install-from-git --url https://github.com/forge/jboss-as-addon  --coordinate org.jboss.forge.addon:jboss-as-wf

Now you will need to set up at first the application server version to be used with:

as-setup --server wildfly --version 10.1.0.Final

And finally, you can deploy it with:

as-deploy

Here is your application up and running:

jboss forge tutorial

Please note that on some versions of Linux (such as Fedora 21) you can incur in issues when installing the jboss-as-addon, due to an excessive number of io watches created. In order to cope with it (if you really don't want to install the Maven WildFly plugin :-)!) you can increase that number with:

$ sudo sysctl fs.inotify.max_user_watches=20000

Follow us on Twitter