Skip to main content

Java EE 7 Hands-on Lab on WildFly and OpenShift (Tech Tip #33)

Posted by arungupta on June 25, 2014 at 9:16 PM PDT

Thanks to @dmueller for inspiring this blog entry and @FarahJuma for keeping WildFly cartridge continuously updated!

Java EE 7 hands-on lab has been delivered at several conferences, meetups, Java User Groups, and other venues around the world. It provides instructions for a typical 3-tier application using several technologies in the Java EE 7 platform, such as WebSocket 1.0 (JSR 356), Batch Applications (JSR 352), JSON-P 1.0 (JSR 353), JAX-RS 2.0 (JSR 339), JMS 2.0 (JSR 343), CDI 1.1 (JSR 346), JPA 2.1 (JSR 338), and many more. The self-paced instructions allows the attendees to learn the design patterns in Java EE 7, and be productive right away.

This lab can be built using NetBeans, JBoss Tools/Eclipse, or IntelliJ. The deployment can be done on WildFly or GlassFish.

Do you want to get a taste of the application without trying out all the steps ? You can download the solution and deploy on application server of your choice.

Don't have time for downloading and installing your application server ? OpenShift is your answer!

OpenShift provides an open source hybrid cloud application platform by Red Hat. It enables polyglot applications to be deployed on a public, private, and a hybrid cloud very easily. It provides an extensible cartridge-based architecture that allows a wide range of functionality such as frameworks, databases, monitoring services, or connectors to external backends to be easily added. WildFly cartridge allows you to start a WildFly instance in OpenShift Online.

This Tech Tip shows how to deploy Java EE 7 hands-on lab solution easily on WildFly cartridge on OpenShift.

  1. Register for a free OpenShift account.
  2. Login to OpenShift Console.
  3. Create a new WildFly application using the quickstart. Take the defaults, or change the name to whatever you want, and click on "Create Application". The following page is shown:

    techtip33-app-created-creds

    The default application page looks like:

    techtip33-wildfly-default-output

  4. Clone the workspace using the credentials shown for your application.
  5. Delete the generated "src" directory and copy the "src" from solution.
    javaee7lab> git rm -rf src
    rm 'src/main/java/.gitkeep'
    rm 'src/main/resources/.gitkeep'
    rm 'src/main/webapp/images/jbosscorp_logo.png'
    rm 'src/main/webapp/index.html'
    rm 'src/main/webapp/snoop.jsp'
    javaee7lab> cp -r ~/Downloads/movieplex7/src .
  6. Commit and push the changes to restart the cartridge:
    javaee7lab> git add src
    javaee7lab> git commit src -m"updating source directory with Java EE 7 lab contents"
    [master f6f24ec] updating source directory with Java EE 7 lab contents
    53 files changed, 3955 insertions(+), 584 deletions(-)
    delete mode 100644 src/main/java/.gitkeep
    create mode 100644 src/main/java/org/javaee7/movieplex7/batch/SalesBean.java
    create mode 100644 src/main/java/org/javaee7/movieplex7/batch/SalesProcessor.java
    . . .

    create mode 100644 src/main/webapp/chat/websocket.js
    create mode 100644 src/main/webapp/client/addmovie.xhtml
    create mode 100644 src/main/webapp/client/movie.xhtml
    create mode 100644 src/main/webapp/client/movies.xhtml
    delete mode 100644 src/main/webapp/images/jbosscorp_logo.png
    delete mode 100644 src/main/webapp/index.html
    create mode 100644 src/main/webapp/index.xhtml
    create mode 100644 src/main/webapp/points/points.xhtml
    create mode 100644 src/main/webapp/resources/css/cssLayout.css
    create mode 100644 src/main/webapp/resources/css/default.css
    delete mode 100644 src/main/webapp/snoop.jsp
    javaee7lab> git push
    warning: push.default is unset; its implicit value is changing in
    Git 2.0 from 'matching' to 'simple'. To squelch this message
    and maintain the current behavior after the default changes, use:

      git config --global push.default matching

    To squelch this message and adopt the new behavior now, use:

      git config --global push.default simple

    See 'git help config' and search for 'push.default' for further information.
    (the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
    'current' instead of 'simple' if you sometimes use older versions of Git)

    Counting objects: 81, done.
    Delta compression using up to 8 threads.
    Compressing objects: 100% (65/65), done.
    Writing objects: 100% (76/76), 25.06 KiB | 0 bytes/s, done.
    Total 76 (delta 38), reused 0 (delta 0)
    remote: Stopping wildfly cart
    remote: Sending SIGTERM to wildfly:146819 ...
    remote: Building git ref 'master', commit f6f24ec
    remote: Found pom.xml... attempting to build with 'mvn -e clean package -Popenshift -DskipTests'
    remote: Apache Maven 3.0.4 (r1232336; 2012-12-18 14:36:37-0500)
    remote: Maven home: /usr/share/java/apache-maven-3.0.4
    remote: Java version: 1.7.0_55, vendor: Oracle Corporation
    remote: Java home: /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.55/jre
    remote: Default locale: en_US, platform encoding: ANSI_X3.4-1968
    remote: OS name: "linux", version: "2.6.32-431.20.3.el6.x86_64", arch: "i386", family: "unix"
    remote: [INFO] Scanning for projects...
    remote: [INFO]                                                                        
    remote: [INFO] ------------------------------------------------------------------------
    remote: [INFO] Building javaee7lab 1.0
    remote: [INFO] ------------------------------------------------------------------------
    remote: Downloading: http://mirror1.ops.rhcloud.com/nexus/content/groups/public/org/apache/ma.... . .

    remote: Downloaded: http://mirror1.ops.rhcloud.com/nexus/content/groups/public/xpp3/xpp3_min... (25 KB at 204.8 KB/sec)
    remote: Downloaded: http://mirror1.ops.rhcloud.com/nexus/content/groups/public/org/codehaus/... (227 KB at 2077.0 KB/sec)
    remote: [INFO] Packaging webapp
    remote: [INFO] Assembling webapp [javaee7lab] in [/var/lib/openshift/53ab65bee0b8cdf9d1000354/app-root/runtime/repo/target/javaee7lab]
    remote: [INFO] Processing war project
    remote: [INFO] Copying webapp resources [/var/lib/openshift/53ab65bee0b8cdf9d1000354/app-root/runtime/repo/src/main/webapp]
    remote: [INFO] Webapp assembled in [508 msecs]
    remote: [INFO] Building war: /var/lib/openshift/53ab65bee0b8cdf9d1000354/app-root/runtime/repo/deployments/ROOT.war
    remote: [INFO] ------------------------------------------------------------------------
    remote: [INFO] BUILD SUCCESS
    remote: [INFO] ------------------------------------------------------------------------
    remote: [INFO] Total time: 51.727s
    remote: [INFO] Finished at: Wed Jun 25 22:23:46 EDT 2014
    remote: [INFO] Final Memory: 10M/152M
    remote: [INFO] ------------------------------------------------------------------------
    remote: Preparing build for deployment
    remote: Deployment id is 026b1012
    remote: Activating deployment
    remote: Deploying WildFly
    remote: Starting wildfly cart
    remote: Found 127.11.132.129:8080 listening port
    remote: Found 127.11.132.129:9990 listening port
    remote: CLIENT_MESSAGE: Could not connect to WildFly management interface, skipping deployment verification
    remote: -------------------------
    remote: Git Post-Receive Result: success
    remote: Activation status: success
    remote: Deployment completed with status: success
    To ssh://53ab65bee0b8cdf9d1000354@javaee7lab-milestogo.rhcloud.com/~/git/javaee7lab.git/
       75b5640..f6f24ec  master -> master

Refreshing the page at javaee7lab-milestogo.rhcloud.com now shows the application deployed successfully:

techtip33-javaee7lab-default-output

Simple, isn't it ?

Try it and let us know your feedback!

Tech Tip #21 also talks about how to get started with WildFly in OpenShift and JBoss Developer Studio.