Creating your first Java EE 6 application with JBoss Forge

So installation was just a breeeze, however creating your first Java EE 6 application will be even faster! This is our tasklist:

  • Create a new project named as7forge
  • Turn it into a Web project which uses JSF+CDI+JPA
  • Add a sample Entity Class
  • Build and install on JBoss AS 7

So let's move to the Forge shell and, as first move, enable project defaults which will speed up our project creation by automatically selecting defaults for every option:

set ACCEPT_DEFAULTS true;                        

Then let's create our project named as7forge which is based on the top level package com.sample:

new-project --named as7forge --topLevelPackage com.sample                                  

Next we will install the default persistence.xml for JBoss AS 7 bound at java:jboss/datasources/ExampleDS

persistence setup --provider HIBERNATE --container JBOSS_AS7 ;

Good. Now we will add a sample Entity named Customer in the package com.sample.model which is made up of four fields:

entity --named Customer --package ~.model;
field string --named name;
field string --named surname;
field temporal --type DATE --named birthDate;
field string --named city;

Please notice that this command will place you in the scope, where you can issue commands like "ls" to navigate through the Entity class:

[as7forge] $ ls


public::equals(Object that)::boolean
public::setBirthDate(final Date birthDate)::void
public::setCity(final String city)::void
public::setId(final Long id)::void
public::setName(final String name)::void
public::setSurname(final String surname)::void
public::setVersion(final int version)::void

Once created the model we will start scaffolding which means we will create the CRUD (create, read, update, delete) pages for the model:

scaffold setup --scaffoldType faces;  

Now execute:

scaffold from-entity ~.model.* --scaffoldType faces --overwrite; 

This will generate the CRUD pages for your model. We are done! Let's build our project using the "build" command:


Now it's time to deploy the project on JBoss AS 7. JBoss Forge in an extensible platform so, if you want to interact with JBoss AS (any release) , you need to install the AS7 Forge Plugin by typing the following command:

forge install-plugin jboss-as-7

Next, set up the plugin in your project by issuing:

as7 setup

Great we are done. Now start JBoss AS 7 and deploy the application using, from the Forge shell:

as7 deploy

Verify that your application has been correctly deployed by surfing on http://localhost:8080/as7forge/

jboss forge tutorial

Click on the Customer Button and start inserting some data in it:

jboss forge tutorial

The sample application includes also a GUI for viewing / modifying the data:

jboss forge tutorial