IBM WebSphere Application Server (WAS) is a software framework and middleware developed by International Business Machines Corporation. It hosts Java-based web applications and is built using Open standards such as Java EE, XML, and Web Services. WebSphere Application Server is released under a commercial license.

The following post illustrates a basic example in which we will configure, build and run a Hello World PrimeFaces example using WebSphere Application Server and Maven.

If you don’t have an instance of WebSphere Application Server installed on your machine, you can download the developers edition that can be used for development and testing purposes at no charge. Click on the 'Download' button and login with your IBM ID (register one if needed).

Download and extract the Installation Manager for your operating system. Launch the IBM Installation Manager and click through the different setup steps and start the installation. When the installation is complete select the option to launch the 'Profile Management Tool to create an application server profile for a development environment'.

Once the Profile Management Tool is launched, enable administrative security as shown below. In this example we will use following values: User name=”admin” and Password=”admin”.

On the last step leave the 'Launch the First steps console' selected and finish. A new window will pop-up from which you can select the 'Installation verification' link which will launch a first steps output console that prints a number of details on your newly created development server profile.

Once 'Server launched' is printed, open a web browser and enter following URL: http://localhost:9060/ibm/console. After entering the credentials that were defined during the profile setup (in this example User ID=”admin” and Password=”admin”), the WebSphere Application Server admin console should open as shown below.

WAS Maven Plugin Configuration

The example code is built and run using Maven. Specified below is the Maven POM file which contains the needed dependencies for JSF and PrimeFaces.

In order to run the Hello World PrimeFaces application, a servlet container is needed and in this example, the IBM WebSphere Application Server implementation will be used. The deployment of the code will be fully automated using following was-maven-plugin. The detailed configuration of the plugin will be explained in the below steps.

In order to be able to run the was-maven-plugin needs a WebSphere Application Server installation. So the first thing we need to set is the '<was.home>' variable with the full path to the WebSphere 'AppServer' directory. In the above example we installed WAS on Windows at the following location: “C:\Program Files (x86)\IBM\WebSphere\AppServer”.

Under the plugin configuration section the '<user>' and '<password>' parameters need to be set with the values assigned during the profile creation when enabling administrative security. These parameters are not needed in case administrative security is not enabled.

The '<host>' parameter specifies the IP/domain URL of the WAS instance on which we will deploy the Hello World application. In this example we will run the Maven command on the same machine as WAS is installed and so we use “localhost” as value.

The '<server>' and '<node>' values can be found by opening the admin console and selecting the 'Servers > Server Types > WebSphere application servers' menu on the left hand side. This opens an overview of all application servers. The 'name' and 'node' columns will contain the server name and node name respectively.

In WebSphere, a virtual host is simply a set of host aliases, where each alias specifies a host name (or a * wildcard to match any host name) and a port number. The names of the available virtual hosts can be found under 'Environment > Virtual hosts' menu, as shown below. In this example we will use 'default_host' as it contains a host alias for port '9080', which is the default port WAS uses to listen for HTTP traffic.

The name of the deployed application will be set to '${project.build.finalName}' which defaults to '${artifactId}-${version}'. In this example this would be: 'jsf-primefaces-websphere-application-server-1.0'. In addition the context path is set to 'codenotfound'.

As WebSphere Application Server ships with its own implementation of the Servlet API and JaveServer Faces we need to set the respective Maven dependencies (javax.servlet-api, jsf-api, jsf-impl) to scope=”provided”. In addition the was-maven-plugin needs to be configured to set the webmodule class loader policy to parent last. This can be achieved by setting '<parentLast>' to “true”.

Note that WebSphere Application server 8.5 by default runs on JDK 1.6. This is why the maven-compiler-plugin has been configured to compile to “1.6”. Specifying a higher Java version will result following error message when trying to start the application:
java.lang.UnsupportedClassVersionError: JVMCFRE003 bad major version; class=com/codenotfound/primefaces/HelloWorld, offset=6.

Running the Hello World Example

In order to run the above example open a command prompt and execute following Maven command:

mvn install

Depending on where WebSphere Application Server is installed, you might need to execute the above command with the correct privileges. For example when running on Windows 7 with the default installation location, not running as an administrator results in following error message:
!MESSAGE Error reading configuration: C:\Program Files (x86)\IBM\WebSphere\AppServer\profiles\AppSrv01\configuration\org.eclipse.osgi\.manager\.fileTableLock (Access is denied.).

Maven will download the needed dependencies, compile the code and connect to the WAS server. In a first step, a check is done to see if the application is already installed. If so then an uninstall command is triggered to remove the previous version. In a next step, the application is installed and started. Finally, the application server is restarted resulting in a successful build and deploy as shown below.

Open the WAS admin console and navigate to 'Applications > Application Types' > WebSphere enterprise applications'. The example application should now be shown in the list of installed application (jsf-primefaces-websphere-application-server-1.0) with a green arrow beside it which indicates it was successfully started.