Skip to content

Commit

Permalink
sync
Browse files Browse the repository at this point in the history
  • Loading branch information
ctomc committed Jun 1, 2017
1 parent 29453c9 commit 3588f82
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ bin
.clover
*.swp
!/wicket-war/src/main/resources/META-INF/MANIFEST.MF

build.metadata

This file was deleted.

124 changes: 124 additions & 0 deletions forge-from-scratch/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# forge-from-scratch: Shows How Forge Can Generate an Application

Author: Lincoln Baxter, Matej Briskar
Level: Intermediate
Technologies: Forge
Summary: The `forge-from-scratch` quickstart demonstrates how *JBoss Forge* can generate a Java EE (JPA, EJB, JAX-RS, JSF) web-enabled database application.
Target Product: ${product.name}
Source: <${github.repo.url}>

## What is it?

The `forge-from-scratch` quickstart demonstrates how to create a fully **Java EE compliant** project using **JBoss Forge** and **Red Hat JBoss Developer Studio** and deploy it to **${product.name.full} ${product.version}** or later.

The generated example will be a standard Maven, Java Web project with **JPA, EJB, CDI, JSF** 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.

_Note: This quickstart uses the H2 database included with ${product.name.full} ${product.version}. It is a lightweight, relational example datasource that is used for examples only. It is not robust or scalable, is not supported, and should NOT be used in a production environment!_

## System Requirements

The application this project produces is designed to be run on ${product.name.full} ${product.version} or later.

All you need to build this project is Java 8.0 (Java SDK 1.8) or later and Red Hat JBoss Developer Studio 10.0 or greater. These versions of JBoss Developer Studio embed Maven 3.3.3, so you do not need to install it separately.


## Run the Quickstart in Red Hat JBoss Developer Studio

JBoss Developer Studio 10.3 ships with Forge 3.5.1.Final.

### 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. At this point, Forge creates the new project and builds it.
* The script issues this command: `$ project-new --named forge-example --top-level-package org.example;`
* You next see the console message: `***SUCCESS*** Project named 'forge-example' has been created.`
* This is followed by a number of commands that set up JPA, create an entity and its fields, set up and generate the scaffold, and set up CDI and REST. Each command should result in a `***SUCCESS***` message.
* Finally, the `build` command is executed, which should result in `***SUCCESS*** Build Success` near the end of the console output.

_NOTE:_ After you run the `run generate.fsh` command, you will see the following warnings in the *Problems* window for the generated files. You can ignore these warnings.

Web XML Problem: location references to "/faces/error.xhtml" that does not exist in web content web.xml /forge-example/src/main/webapp/WEB-INF line 17
Web XML Problem: location references to "/faces/error.xhtml" that does not exist in web content web.xml /forge-example/src/main/webapp/WEB-INF line 21
JPA Problem: No connection specified for project. No database-specific validation will be performed. forge-example


### What Did This Create?

This quickstart created a native Java EE 7 application.

* After the command completes, look in your `QUICKSTART_HOME/forge-from-scratch/` folder. You see a folder with the name `forge-example`.
* This project also appears in the `Project Explorer` view in JBoss Developer Studio.
* Browse through this project to see the code that was generated as a result of this command.

### Deploy the Generated Application

1. If you have not yet done so, add the ${product.name} ${product.version} runtime server to Red Hat JBoss Developer Studio. For general information about how to import a quickstart, add a ${product.name} server, and build and deploy a quickstart, see [Use JBoss Developer Studio or Eclipse to Run the Quickstarts](https://github.com/jboss-developer/jboss-developer-shared-resources/blob/master/guides/USE_JBDS.md).
2. Right-click on the project name and choose `Run As` --> `Run on Server`. If you have more than one server, choose the ${product.name} ${product.version} Runtime server. Then click `Finish`.
3. Upon successful deployment, a **Welcome to Forge Window** opens with the application running at the following URL: <http://localhost:8080/forge-example/>

### Server Log: Expected warnings and errors

_Note:_ You will see the following warnings in the server log. You can ignore these warnings.

WFLYTX0013: Node identifier property is set to the default value. Please make sure it is unique.
WFLYDM0111: Keystore /home/user/eap-7.1/standalone/configuration/application.keystore not found, it will be auto generated on first use with a self signed certificate for host localhost
HHH000059: Defining hibernate.transaction.flush_before_completion=true ignored in HEM
HHH000431: Unable to determine H2 database version, certain features may not work


### Access the Running Application

The application appears in a 'Welcome to Forge' Window and displays the following:

Welcome to Forge

Your application is running.

The following entities are displayed on the lower left side of the page:

* Address
* Customer
* Item
* Product Order
* Profile
* Zip Code

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 ${product.name}:


1. Go to the Red Hat JBoss Developer Studio `Servers` window.
2. Expand the ${product.name} Server to see the list of deployed applications.
3. Choose the `forge-example` project created by this quickstart, right-click, and choose `Remove`.
4. Click `OK` when asked if you are sure you want to remove resource from the server. You should see the following message:

INFO [org.jboss.as.server] (DeploymentScanner-threads - 1) WFLYSRV0009: Undeployed "forge-example.war" (runtime-name: "forge-example.war")



## 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.
68 changes: 68 additions & 0 deletions forge-from-scratch/generate.fsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Example Forge Script - Generates a Point-of-sale Style Application;
# NOTE: This script is compatible with Forge 3.x only and will not run in Forge 2.x

# Clear the screen;
clear;

# Create a new project in the current directory;
project-new --named forge-example --top-level-package org.example;

# Setup JPA in our project;
jpa-setup --provider Hibernate --container JBOSS_EAP7;

# Create some JPA @Entities on which to base our application;
jpa-new-entity --named Customer --target-package org.example.domain;
jpa-new-field --named firstName;
jpa-new-field --named lastName;
jpa-new-field --named birthDate --type java.util.Date;
jpa-new-entity --named Item;
jpa-new-field --type String --named name;
jpa-new-field --named price --type java.lang.Double;
jpa-new-field --named stock;
cd ..;

# Create more entities, also add a relationship between Customer and their Orders;
jpa-new-entity --named ProductOrder;
jpa-new-field --named customer --type org.example.domain.Customer --relationship-type Many-to-One --inverse-field-name orders;
cd ../Customer.java;
jpa-new-entity --named Profile;
jpa-new-field --type String --named bio;
jpa-new-field --type String --named preferredName;
jpa-new-field --type String --named notes;
jpa-new-entity --named Address;
jpa-new-field --type String --named street;
jpa-new-field --type String --named city;
jpa-new-entity --named ZipCode;
jpa-new-field --type int --named code;
cd ../Address.java;

# Add more relationships between our @Entities;
jpa-new-field --named zip --type org.example.domain.ZipCode --relationship-type Many-to-One;
cd ../Customer.java;
jpa-new-field --named addresses --type org.example.domain.Address --relationship-type Many-to-Many;
jpa-new-field --named profile --type org.example.domain.Profile --relationship-type Many-to-One;
cd ../ProductOrder.java;
jpa-new-field --named items --type org.example.domain.Item --relationship-type Many-to-Many;
jpa-new-field --named shippingAddress --type org.example.domain.Address --relationship-type Many-to-One;
cd ..;

#Turn our Java project into a Web project with JSF, CDI, EJB, and JPA;
scaffold-setup --provider Faces --faces-version 2.1;

# Enable CDI if not already done;
cdi-setup;

# Generate the UI for all of our @Entities at once;
scaffold-generate --provider Faces --overwrite --targets org.example.domain.*;
cd ~~;

# Setup JAX-RS, and create CRUD endpoints;
rest-setup;
rest-generate-endpoints-from-entities --targets org.example.domain.*


# Build the project and disable ACCEPT_DEFAULTS;
build;

# Return to the project root directory and leave it in your hands;
cd ~~;
10 changes: 3 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<jboss.home.name>WILDFLY_HOME</jboss.home.name>
<product.name>WildFly</product.name>
<!-- A base list of dependency and plug-in version used in the various quick starts. -->
<version.wildfly.maven.plugin>1.2.0.Alpha2</version.wildfly.maven.plugin>
<version.wildfly.maven.plugin>1.2.0.Alpha4</version.wildfly.maven.plugin>

<!-- other plug-in versions -->
<version.com.mycyla.license>3.0</version.com.mycyla.license>
Expand All @@ -57,16 +57,12 @@
filtered resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<version.spring.framework>4.3.6.RELEASE</version.spring.framework>
<version.spring.framework>4.3.7.RELEASE</version.spring.framework>
<!-- EAP component version management BOM -->
<version.server.bom>11.0.0.Alpha2</version.server.bom>

<version.jboss.spec.javaee.7.0>1.1.0.Final</version.jboss.spec.javaee.7.0>

<!-- maven-compiler-plugin -->
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>

<version.jaxws-tools-maven-plugin>1.2.0.Final</version.jaxws-tools-maven-plugin>

<!-- Other dependency versions -->
Expand Down Expand Up @@ -802,7 +798,7 @@
<inputEncoding>UTF-8</inputEncoding>
<headerHtmlFile>${root.dir}/dist/header.html</headerHtmlFile>
<footerHtmlFile>${root.dir}/dist/footer.html</footerHtmlFile>
<pegdownExtensions>TABLES,TOC,AUTOLINKS,STRIKETHROUGH,ATXHEADERSPACE,FENCED_CODE_BLOCKS</pegdownExtensions>
<pegdownExtensions>TABLES,TOC,AUTOLINKS,STRIKETHROUGH,ATXHEADERSPACE,FENCED_CODE_BLOCKS,HARDWRAPS,ANCHORLINKS,RELAXEDHRULES</pegdownExtensions>
<!--<copyDirectories>css,js</copyDirectories>-->
<transformRelativeMarkdownLinks>true</transformRelativeMarkdownLinks>
</configuration>
Expand Down

0 comments on commit 3588f82

Please sign in to comment.