Wednesday, November 5, 2014

Using WebSphere Liberty Maven Archetypes

In a previous post I outlined how I setup Eclipse Luna and Maven for development with WebSphere Liberty.  In this post, I would like to explore the Maven Archetypes that are provided for the Liberty Profile by IBM.

When you install the WebSphere Liberty Profile Developer Tools from the Eclipse Marketplace, the location of the IBM provided Maven Archetypes is automatically added to the list of Archetype Catalogs in the Eclipse Maven preferences.  This can be verified by accessing Window > Preferences > Maven > Archetypes.  In this dialog, you should see something along the lines of this:


I have highlighted the IBM entry in the screen shot above.

IBM has provided three primary Archetypes; EJB, OSGi and WebApp (Portlet is there as well).  For each of these, there is a JEE 5 and JEE 6 version for both the Liberty Profile and WebSphere proper.  To use these Archetypes to create a new project, simply:

  1. Access File > New > Project... and scroll down to and expand the Maven entry.  
  2. Choose the Maven Project entry from the list.
  3. Click the Next button.
  4. On the New Maven Project dialog, click the Next button.
  5. From the Catalog selection menu, select the IBM catalog.
At this point, the new project dialog should look something like this:


To complete the process, select the Archetype that best meets the need of the project and click the Next button.  On the final screen, enter the Maven specifics of the project and click Finish.

If you followed the instructions from my previous post, your project should be created successfully using the dependency created by the pom builder.

Tuesday, November 4, 2014

Using Eclipse Luna and Maven with WebSphere Liberty v8.5.5.3

I seem to have trouble getting the development tools that are available in the Eclipse Marketplace for WebSphere Liberty to work with Eclipse Luna and Maven on Fedora 20.  The issues and errors I'm seeing might exist on any OS, but I haven't tried on anything but Fedora.  The server management aspect of the development tools works great.  Creating servers, starting / stopping servers, deploying applications, etc...  all works without issue.  When I want to create a Maven project using the provided archetypes is where I start to run into trouble.  This post outlines the steps I've taken to get around these issues.

Tools

First, I installed the following:
  • WebSphere Liberty Profile (v8.5.5.3)
  • Eclipse Luna for JEE Developers (comes with the maven plugin)
  • Maven (v3.2.3)

Maven Configuration

Next I configure Eclipse to use the version of Maven I just installed instead of the bundled version by:

  1. Going to Window > Preferences > Maven > Installations.  
  2. Clicking the Add... button.
  3. Setting the Installation type to external.
  4. Clicking the Directory button and browsing to the location where I installed Maven.
  5. Clicking OK.
The resulting dialog should look something like this:


Click Finish to complete the configuration.  Back on the Maven Installation Preference dialog, I select the entry I just created.



Finally, I click OK to apply the changes and close the Preferences window.

WebSphere Liberty Profile Developer Tools

Next I install the WebSphere Liberty Profile Development Tools from the Eclipse Marketplace by:
  1. Clicking on Help > Eclipse Marketplace...
  2. Typing into the Find field a search of Liberty.
  3. Scrolling down the result list to the entry titled IBM WebSphere Application Server Liberty Profile Developer Tools for Luna.
  4. Clicking the Install button.
  5. When enabled, clicking the Confirm button.
  6. Accepting the license agreement and clicking Finish.
The plugin installs and prompts me to restart Eclipse and I click the Yes button to execute.  

Note: Sometime I get an error during the installation.  When this happens, I delete the artifacts.xml file from within the installation directory of Eclipse and restart Eclipse using the -clean command line argument.

Configuring JEE Maven Project Settings

I like to use the maven directory structure for all of my projects.  This structure is not the default structure used by Eclipse though and can cause issues with dynamic web projects.  This can be updated byt:
  1. Accessing Windows > Java EE > Maven > Maven Project Settings.
  2. Click the Set all Maven values button at the top of the screen.
  3. Click the Apply button at the bottom of the screen.
New JEE projects will now be created using the default maven directory structure.

Configuring settings.xml for Maven

Update:  This feature now working with the latest release of the plugin.  Execute the following steps:

  1. From within Eclipse, access Windows > Preferences > Java EE > Maven > Maven Repository Initialization.
  2. Click on the configure button.
This will create / update your local setting.xml file to include the IBM Maven repository.


This is where I usually start running into issues.  The first step is to configure my Maven settings.xml file with the location of the IBM Maven repository for WebSphere.  I should be able to access Windows > Preferences > Java EE > Maven > Maven Repository Initialization and have the Liberty plugin configure my settings.xml for me, but this fails with the following error:



Since this steps fails in Eclipse, I do it manually by:
  1. Coping the global settings.xml from the conf directory of the Maven installation directory to my user's .m2 directory.  (For example:  cp /opt/apache-maven-3.2.3/conf/settings.xml ~/.m2/.)
  2. Opening my settings.xml is a text editor.
  3. Add the following XML snippet to the <profiles> element:
  4. Add was-dev-profile to the active profiles list:
  5. Save the changes and close the text editor.

Populating My Local Repository

The Liberty plugin comes with Maven POM files that can be used to populate a user's local Maven repository with the libraries that are installed with the Liberty profile.  I use these POM files to populate my local repository by:
  1. Using a terminal window to access the Liberty plugin's installation directory within the Eclipse installation directory (For example: /opt/eclipse/plugins/com.ibm.etools.maven.javaee.core_1.1.1.v20140602_0512).
  2. Using the terminal window to locate the Liberty plugin installer pom.xml (For example: /opt/eclipse/plugins/com.ibm.etools.maven.javaee.core_1.1.1.v20140602_0512/resources/scripts/Liberty 8.5.5 Fix Pack 1 Plugins installer)
  3. Using Maven to execute the pom.xml in this directory.  I have to pass a property containing the installation directory of Liberty to Maven. (For example: mvn install -DserverInstallationFolder=/opt/IBM/WebSphere/Liberty)
Unfortunately, pom files are only provide in support of v8.5.5.0 and v8.5.5.1.  The maven build resulted in an error for me with v8.5.5.3 because the names of the individual jars files provided by Liberty include the version number and that version number can change with each release.  To get around this issue, I created a simple Java program that will build POM files for me based on the installed version of Liberty.  I have the code for the tool available on GitHub with instructions on how to use it:

https://github.com/tglawless/jee/tree/master/was-pom-builder