Red Hat

Developer Materials

forge-from-scratch: Example Showing How Forge Can Generate an Application From Scratch

  • Author: Lincoln Baxter
  • Contributors: Sande Gilda, Pete Muir , Lincoln Baxter, III
  • Published: Mar 17, 2014
  • Level: Intermediate
  • Technologies:Forge
  • Target Product:EAP

What is it?

This quickstart demonstrates how to create a fully Java EE compliant project using nothing but JBoss Forge.

Once generated, the sample project will be a standard Maven 3, Java Web project with JPA 2.0, EJB 3.1, CDI 1.0, JSF 2.0 with complete JAX-RS endpoints for all data Entities. It will also provide views to Create, Read, Update, and Delete records.

But that is not all! You can use Forge on your new or existing projects to continue to enhance any application.

System requirements

The application this project produces is designed to be run on Red Hat JBoss Enterprise Application Platform 6.1 or later.

All you need to build this project is Java 6.0 (Java SDK 1.6) or later and JBoss Developer Studio (JDBS) 7 or greater.

Configure Maven for JBoss Developer Studio

If you have not yet done so, you must Configure Maven for JBoss Developer Studio before testing the quickstarts.

Run the Quickstart in JBoss Developer Studio

Forge is available in JBoss Developer Studio. To run this example, we suggest you use JDBS 7 or greater.

Generate and Build the Application

  1. Start JBoss Developer Studio.
  2. Open the Forge Console Window. To open it, navigate to menu item Window -> Show View -> Other. Locate Forge -> Forge Console and click OK.
  3. Click the Start button (green triangle) in top right corner of the Forge Console to start the default Forge runtime.
  4. In the Forge Console Window, navigate to the root directory of this quickstart.

     $ cd QUICKSTART_HOME/forge-from-scratch/
  5. Notice there is a file in this directory named generate.fsh. Run this file from the Forge console using the run command:

     $ run generate.fsh
  6. You are prompted to enter the name of the new project. Type a name for the project, for example: example-application

     ? [named=The name of the new project (of type java.lang.String)]: example-application
  7. You are prompted to accept QUICKSTART_HOME/forge-from-scratch/example-application as the project directory. Choose Y:

     ? Use [/home/username/QUICKSTART_HOME/forge-from-scratch/example-application] as project directory? [Y/n] Y
  8. At this point, Forge creates the new project and builds it.
    • You see console messages starting with ***SUCCESS***
    • This is followed by a dialog saying User Operation is waiting for "Importing Forge project" to complete..
    • Finally, you see a [INFO] BUILD SUCCESS message near the end of the console output.

What Did This Create?

This quickstart created a native Java EE 6 application.

  • After the command completes, look in your QUICKSTART_HOME/forge-from-scratch/ folder. You see a folder with the same name as the project name you entered in the prompt above.
  • This project also appears in the Project Explorer view in JDBS.
  • Browse through this project to see the code that was generated as a result of this command.

For a full description of what was generated by running this script and details on the structure of the application, see the Forge UI Scaffolding Guide

Deploy the Generated Application

  1. If you have not yet done so, add the JBoss EAP 6.3 runtime server to JDBS. For more information, see Set Up the Development Environment.
  2. Right mouse on the project name and choose Run As –> Run on Server. If you have more than one server, choose the JBoss EAP 6.3 Runtime server.
  3. Upon successful deployment, a Welcome to Forge Window opens with the application running at the following URL: http://localhost:8080/PROJECT_NAME/, where PROJECT_NAME is the name you chose for your project. For example:


Access the Running Application

The application Window displays the following messages

    Welcome to Forge
    Your application is running. 

A list of entities is displayed on the left of the screen. When you click on an entity, you are provided with a form that allows you to:

  • Search for an existing entity
  • Create a new entity
  • Edit or delete an existing entity

The running application also provides links to find more information about the Forge.

Undeploy the Application

When you are ready to undeploy the application from JBoss EAP:

  1. Go to the JDBS Servers window.
  2. Expand the JBoss EAP 6.3 Server to see the list of deployed applications.
  3. Choose the project you created using this quickstart, right mouse, and choose Remove.
  4. Click OK when asked if you are sure you want to remove resource from the server.

Next Steps

Open generate.fsh and take a look inside! There is not much magic happening here. All of the commands used to generate this project are clearly listed just as if they were typed by your own hands.

Play around with creating more entities, relationships, UI, and generating JAX-RS endpoints,all with just a few simple commands.

Explore plugins!

Forge has a rich plugin ecosystem. Want to deploy your application to the Cloud? Use the Forge Openshift plugin:

To see a full list of avaialable plugins, make sure that you have an active internet connection and type:

    forge> forge find-plugin *

Recent Changelog

  • Mar 17, 2014(Sande Gilda):Bz1077218 Update instructions for forge from scratch quickstart
  • Mar 12, 2014(Sande Gilda):Bz1074530 replace JBOSS_HOME with EAP_HOME
  • Mar 2, 2014(Sande Gilda):Bz1025766 Replace JBoss with JBoss EAP
  • Feb 14, 2014(Sande Gilda):Replace JDBS instructions with shared resource
  • Jan 28, 2014(Sande Gilda):JDF 602 Part 2 of changes to move common instructions to a shared repository. This commit contains the Maven Configuration link changes
  • Dec 16, 2013(Sande Gilda):JDF 577 Replace command line with command prompt when referring to a terminal
  • Nov 8, 2013(Sande Gilda):Bz1028448 Add spaces to end of metadata so it renders with a line break in HTML
  • Oct 2, 2013(Sande Gilda):README add Product Versions metadata remove versions in text remove temp repo from settings.xml
  • Sep 24, 2013(Sande Gilda):Remove references to web profile
  • Sep 24, 2013(Sande Gilda):Remove references to JBoss AS 7 from the quickstarts
Your Rating: