How to run the open source Java EE 7 samples on WAS Liberty.

How to run the open source Java EE 7 samples on WAS Liberty.

Authored by Alex Motley, Daniel Clarke, and Ryan Brink

What are the Java EE samples?

The samples are an open source Github project showing off the awesome capabilities of Java EE 7. Although originally developed for the Glassfish Reference Implementation, they have since been used by other application servers, including WAS Liberty, to demonstrate the Java EE 7 features.

The samples are run using Maven with an Arquillian testing framework. The samples contain a mix of unit tests and interactive web interfaces. A strong background using Arquillian is not needed to run the samples, but if you are interested we have a great tutorial on using Arquillian with Liberty.

Set up the Samples on your workstation:

  1. Install the current version of Maven, JDK 7 (minimum), and Liberty Full Platform or the latest Liberty Beta Full Platform on your workstation.
  2. Download the samples from the Github repository (either by downloading a zip file of the samples or cloning the repository in your workspace).

You are now ready to run the samples!

Running the Samples

The samples are run through the command line using Maven. There are instructions on how to run the samples using the various profiles in the project readme, but we have provided the instructions for Liberty below for ease. To run the samples they first need to be built. To build the samples run the following command from the parent sample folder (javaee7-samples if the repository was cloned or javaee7-samples-master if the zip file was downloaded):

mvn clean install -Pliberty-managed-arquillian -DlibertyManagedArquillian_wlpHome=path to Liberty installwlp  -DskipTests

The server.xml needed to run each sample will vary based on which sample, or samples, are running, but be sure to include the following code which is needed for all of the samples:


    <keyStore id="defaultKeyStore" password="yourPassword"/>

    <basicRegistry id="basic" realm="customRealm">
        <user name="user" password="password"/>

Many of the samples also require a data source to be defined to run. Add the code below to the server.xml add a data source for Derby to the samples. Note that you’ll need to place a driver for Derby named derby.jar in a folder named derby in the shared resources folder (wlp/usr/shared/resources/derby).

    <dataSource id="DefaultDataSource">
	  <jdbcDriver libraryRef="DerbyLib"/>  
	  <properties.derby.embedded createDatabase="create" databaseName="${server.config.dir}/resources/DEFAULTDB" password="pass" user="user">
    <library id="DerbyLib">
	 <fileset dir="${shared.resource.dir}/derby" includes="derby.jar"/>

The samples can then be run either all together (from the samples’ parent folder), by technology (from that technology’s folder: e.g. Websockets), or each individual sample (from the individual sample folder: e.g. Websockets/chat). To run the sample(s) navigate to the desired folder and run the following command:

mvn clean install -Pliberty-managed-arquillian -DlibertyManagedArquillian_wlpHome=path to Liberty installwlp

If you want the samples to continue to run even if one test fails add option -fn to the end of the maven command.

Several of the samples also offer an interactive web UI. If the sample has webapp folder containing an index file then it has a web UI. To run these interfaces ensure that the samples have all been built using the command above. Then navigate to the .m2 Repository/org/javaee7/Desired_Sample/1.0-SNAPSHOT directory and copy the sample_name-1.0-SNAPSHOT.war file. Paste this item in the dropins folder of the Liberty server and start the server. The URL for the webapp can be found in the messages.log file.

Do all the Samples run on Liberty?

Not at the moment. Since this is an open source project with many contributors, there are many samples that need some modifications to work on any application server. This is a fluid project which will continue to grow, and the projects will continue to be updated.

This should give you a good idea on how to get started with these Jave EE 7 samples. Comments and suggestions for improvements are welcome.

Join The Discussion

Your email address will not be published. Required fields are marked *