This tutorial is not up to date. It describes an older version of generjee.

Tutorial

Index

1. Introduction - generjee concepts - What is generjee? How does it work?
2. Let's create a Car Repair Shop application
3. Generate
4. Running the generated code on a server

4 Running the generated code on a server

4.1 Start on a local WildFly server

To run the generated application on a local WildFly server, you need to have JDK 7 and Maven installed properly. If you do not have these already set up, please follow the official installation instructions for Oracle JDK 7 and Apache Maven.

If JDK and Maven are installed, please go to the WildFly download page, and download the 8.2.0. Final version. Unpack the files to a folder on your local drive. Then open the folder wildfly-8.2.0.Final/bin and start the standalone.sh (on Unix) or standalone.bat (on Windows). That's it! The server is running now. Test it by entering http://localhost:8080 in your browser. That should open the WildFly server start page without errors.



Now go into the generated CarRepairShop directory and execute the command mvn install wildfly:deploy. This will direct Maven to make a build of the code and to deploy it on the running WildFly server. When you run this command the first time, it may take a few minutes to download all the dependencies. But next time it will be much faster.

After the application is deployed successfully, you can start it in your browser with http://localhost:8080/CarRepairShop. Use the predefined login user="usermanager" and password="password" to create some test users for the different roles. If there seems to be an error, check the log files in wildfly-8.2.0.Final/standalone/log.



4.2 Deploying on OpenShift

The generated code is ready to run on the OpenShift platform. Go to www.openshift.com and sign up for a new free account.

After the account is created, login with your credentials and add a "WildFly Application Server 8.2.0.Final" cartridge.

Now we need to connect to this server using SSH and sFTP, because we want to create a war file on our local drive and then just copy it onto the remote server.

To connect to the server using SSH and sFTP, you will need to have a public-private key. Keep the private key on your local computer, and add the public key to any server you want to have access. You can create a key using puttygen.

Download and install Putty and then open PuttyGen.

Click Generate, then Click "Save private key" to save the private key to your local drive. Now copy the public key content of the text area to your clipboard:



Add the public key to your OpenShift account: Login to OpenShift, go to the Settings page and click on "Add a new key".



Enter any name and the content of the public key into the text area:



Now we want to use FileZilla to copy the war file to the server. So download and install FileZilla. Then start it and add the new private key file to the SFTP settings:



Get the Username and Hostname for the server connection from OpenShift. Get the Hostname from the OpenShift URL of your application, for example "shop-carshop.rhcloud.com". Get the Username from the OpenShift page:



Enter the values into the FileZilla connection fields. Use Port 22 and connect to the server.



Now copy the CarRepairShop.war from CarRepairShop/target to the remote folder app-deployments. If there is no CarRepairShop.war, create it by executing the command mvn package from the CarRepairShop directory.

After the CarRepairShop.war is copied successfully to app-deployments, drop it into the remote directory wildfly/standalone/deployments. WildFly will automatically start the deployment. You can see this happening, because there will be a CarRepairShop.war.isdeploying file for some time in the deployments directory. After the application is deployed, there will be a new file CarRepairShop.war.deployed. You can also check the log files. They are in the folder wildfly/standalone/log.

After deployment is finished, start the application with http//<your-application>.rhcloud.com/CarRepairShop.

4.3 Activate MySQL for the OpenShift application

The generated code uses by default an in-memory H2 datasource, which is preconfigured by WildFly. Now, we will switch to a persistent MySQL database. Open your WildFly server on OpenShift and add a MySQL cartridge to it:



Then be sure you have installed GIT and the OpenShift Client Tools.

Run rhc setup to configure the SSH keys for the remote connection.

Clone the GIT repository of your OpenShift application. Example command is "git clone ssh://55486ec74382ec7e7d000026@repair-carshop.rhcloud.com/~/git/repair.git/"

Remove the "src" folder and the pom.xml file from the new git clone.

Open .openshift/config/standalone.xml and activate the MySQL connection. To do this you only need to set enabled="true":

<datasource jndi-name="java:jboss/datasources/MySQLDS" enabled="true" use-java-context="true" pool-name="MySQLDS" use-ccm="true">

Execute git commit –am "some message" from the git cloned repository. Then execute git push. Wait until the deployment is finished.

Now we need to change the database connection JNDI name within our generated code, and deploy a new package on the OpenShift WildFly server.

Please edit the file CarRepairShop/src/main/resources/META-INF/persistence.xml and change the jta-data-source to java:jboss/datasources/MySQLDS. Then open CarRepairShop/src/main/webapp/WEB-INF/shiro.ini and change the value of datasource.resourceName.

Run the command mvn package from CarRepairShop, copy the updated CarRepairShop/target/CarRepairShop.war to app-deployments on the OpenShift server, and deploy it again.

Now the application is connected with a MySQL database.