Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
branch: master
140 lines (106 sloc) 6.707 kB

Basic Java EE Application using Forge 2

Create an app

This section of the script creates a new Java EE app from scratch using Forge, adds the key Java EE 6 technologies. It adds some pre-canned entities, and scaffolds JAX-RS endpoints.

  1. In the Forge console, create a new project

    project-new --named basic-javaee-forge --topLevelPackage org.forge.samples.javaee
  2. Add some Java EE capabilities:

    servlet-setup; cdi-setup; jpa-setup --container JBOSS_EAP6; rest-setup; constraint-setup; faces-setup; ejb-setup; scaffold-setup
    ***SUCCESS*** Servlet API has been installed.
    [basic-javaee-forge]$ ***SUCCESS*** CDI has been installed.
    [basic-javaee-forge]$ ***SUCCESS*** Persistence (JPA) is installed.
    [basic-javaee-forge]$ ***SUCCESS*** JAX-RS has been installed.
    [basic-javaee-forge]$ ***SUCCESS*** JavaServer Faces has been installed.
    [basic-javaee-forge]$ ***SUCCESS*** Bean Validation is installed.
    [basic-javaee-forge]$ ***SUCCESS*** JavaServer Faces has been installed.
    [basic-javaee-forge]$ ***SUCCESS*** EJB has been installed.
    [basic-javaee-forge]$ ***SUCCESS*** Scaffold was setup successfully.
  3. Add some entities:

    [basic-javaee-forge]$ jpa-new-entity --named Author --targetPackage org.forge.samples.javaee.entities
    ***SUCCESS*** Entity org.forge.samples.javaee.entities.Author created
    [Author.java]$ jpa-new-entity --named Book --targetPackage org.forge.samples.javaee.entities
    ***SUCCESS*** Entity org.forge.samples.javaee.entities.Book created
  4. Each entity is generated with the following fields:

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id", updatable = false, nullable = false)
    private Long id;
    @Version
    @Column(name = "version")
    private int version;

    Add some fields to these entities:

    [Book.java]$ jpa-new-field --named title --type String --length 100
    ***SUCCESS*** Field title created
    [Book.java]$ jpa-new-field --named isbn --type String --length 30
    ***SUCCESS*** Field isbn created
    [Book.java]$ cd ../Author.java
    [Author.java]$ jpa-new-field --named name --type java.lang.String --length 50
    ***SUCCESS*** Field name created
    [Author.java]$ jpa-new-field --named books --type org.forge.samples.javaee.entities.Book --relationshipType One-to-Many
    ***SUCCESS*** Relationship One-to-Many created
  5. Add some Bean Validation constraints:

    [Author.java]$ constraint-add --onProperty name --constraint Size --max 50
    ***SUCCESS*** Constraint Size successfully configured
    [Author.java]$ cd ../Book.java
    [Book.java]$ constraint-add --onProperty title --constraint Size --max 100
    ***SUCCESS*** Constraint Size successfully configured
    [Book.java]$ constraint-add --onProperty isbn --constraint Size --max 30
    ***SUCCESS*** Constraint Size successfully configured
    [Book.java]$ constraint-add --onProperty isbn --constraint Pattern --regexp ^\d{9}[\d|X]$
    ***ERROR*** org.eclipse.jdt.core.dom.MarkerAnnotation cannot be cast to org.eclipse.jdt.core.dom.NormalAnnotation

JSF Scaffold

  1. Generate JSF scaffold endpoints for the entity.

    [Book.java]$ scaffold-generate --targets org.forge.samples.javaee.entities.Author
    ***SUCCESS*** Scaffold was generated successfully.
    [Book.java]$ scaffold-generate --targets org.forge.samples.javaee.entities.Book
    ***SUCCESS*** Scaffold was generated successfully.
  2. Package and deploy the application as:

    mvn clean package
    jboss-cli.sh -c --command="deploy /Users/arungupta/workspaces/forge-samples/basic_javaee/basic-javaee-forge/target/basic-javaee-forge-1.0.0-SNAPSHOT.war --force"
  3. Access the application at http://localhost:8080/basic-javaee-forge-1.0.0-SNAPSHOT/faces/index.xhtml.

REST Scaffold

  1. Generate REST scaffold endpoints for the entity.

    [Author.java]$ rest-generate-endpoints-from-entities --targets org.forge.samples.javaee.entities.Author --packageName org.forge.samples.javaee.rest
    ***SUCCESS*** Endpoint created
    [Author.java]$ rest-generate-endpoints-from-entities --targets org.forge.samples.javaee.entities.Book --packageName org.forge.samples.javaee.rest
    ***SUCCESS*** Endpoint created
  2. Package and deploy the application as:

    mvn clean package
    jboss-cli.sh -c --command="deploy /Users/arungupta/workspaces/forge-samples/basic_javaee/basic-javaee-forge/target/basic-javaee-forge-1.0.0-SNAPSHOT.war --force"
  3. Access the endpoints at http://localhost:8080/basic-javaee-forge-1.0.0-SNAPSHOT/rest/authors and http://localhost:8080/basic-javaee-forge-1.0.0-SNAPSHOT/rest/books.

HTML5 Scaffold (TODO)

1. Generate HTML5 scaffolding - How to install https://github.com/forge/angularjs-addon ?

    scaffold-x setup --scaffoldType angularjs

1. Open up JAX-RS REST Web Services, and locate `GET /rest/session`. Right click on it, and choose *Run As -> Run On Server*. In the Web Service Tester, click the *Play* button, and show the result

1. Generate the CRUD

    scaffold-x from src/main/java/com/redhat/sessions/model/*

Complete Script
---------------

[source,text]
----
project-new --named basic-javaee-forge --topLevelPackage org.forge.samples.javaee
servlet-setup; cdi-setup; jpa-setup --container JBOSS_EAP6; rest-setup; constraint-setup; faces-setup; ejb-setup; scaffold-setup
jpa-new-entity --named Author --targetPackage org.forge.samples.javaee.entities
jpa-new-entity --named Book --targetPackage org.forge.samples.javaee.entities
jpa-new-field --targetEntity org.forge.samples.javaee.entities.Author --named name --type java.lang.String --length 50
jpa-new-field --targetEntity org.forge.samples.javaee.entities.Book --named title --type String --length 100
jpa-new-field --targetEntity org.forge.samples.javaee.entities.Book --named isbn --type String --length 30
constraint-add --javaClass org.forge.samples.javaee.entities.Author --onProperty name --constraint Size --max 50
constraint-add --javaClass org.forge.samples.javaee.entities.Book --onProperty title --constraint Size --max 100
constraint-add --javaClass org.forge.samples.javaee.entities.Book --onProperty isbn --constraint Size --max 30
scaffold-generate --targets org.forge.samples.javaee.entities.Author
scaffold-generate --targets org.forge.samples.javaee.entities.Book
rest-generate-endpoints-from-entities --targets org.forge.samples.javaee.entities.Book --packageName org.forge.samples.javaee.rest
rest-generate-endpoints-from-entities --targets org.forge.samples.javaee.entities.Author --packageName org.forge.samples.javaee.rest
----
Jump to Line
Something went wrong with that request. Please try again.