Create your own simple “Hello World” User Feature

This tutorial is the first of a series of tutorials that will explain how to create, deploy and test a simple user feature with the WebSphere Application Server Liberty Profile V8.5.5.

This tutorial is the first of a series of tutorials that will explain how to create, deploy and test a simple user feature with the WebSphere Application Server Liberty Profile V8.5.5.

Prerequisites

Before you begin please make sure you have downloaded and installed the following:

WebSphere Application Server V8.5.5
WebSphere Application Server Developer Tools for Eclipse Juno V8.5.5

Create a runtime environment and a new server

  1. Select File > New > Other
  2. In the wizard dialog, type this filter text: server
  3. Select the Server wizard and click Next
  4. Choose the server type: WebSphere Application Server V8.5 Liberty Profile
  5. Set the server name: defaultServer
  6. Click Next
  7. Under the installation folder, enter the location where you installed the Liberty Profile runtime environment
  8. Click Finish

You can try starting and stopping this server to test it and to get familiar with the console output. It isn’t configured to do anything so it should start and stop quickly with very little console output.

Tip: you may want to reposition your console pane in Eclipse so that you can see it at the same time as the Servers pane. By default they occupy the same location and you have to switch between them.

Create an OSGi Bundle

This bundle will contain the code for the feature.

  1. File > New > OSGI Bundle Project
  2. Name it: UserFeatureBundle
  3. Set the target runtime as the Liberty Profile runtime environment you created
  4. Do NOT add the bundle to an application (uncheck this option)
  5. Click Next
  6. Click Next
  7. Check the option to generate an Activator
  8. Click Finish

Implement the Bundle

In the newly created project, create a new packaged called “com.ibm.wasdev.tutorial.provider” and inside of that package create a class called “HelloWorld”, with the following code:

package com.ibm.wasdev.tutorial.provider;
    public class HelloWorld {
          public String getHelloWorld() {
               return "Hello World!";
          }
    }

Now open the Activator class and add the following to the start method:

public void start(BundleContext context) throws Exception {
              HelloWorld hw = new HelloWorld();
              System.out.println(hw.getHelloWorld());
        }

Create the Feature

The define this bundle as a user feature we need to do the following:

  1. File > New > Other
  2. Type the filter text: feature
  3. Select the Liberty Feature Project wizard
  4. Set the project name: UserFeature
  5. Choose the Liberty Profile target runtime
  6. Click Next
  7. Ensure that the previously created bundle is selected
  8. Click Finish

Install the bundle

The installation of features has been made significantly easier by the V8.5.5 tooling, all that is now required is to:

  1. Right-click on the Liberty Feature Project that we just created and choose install feature…
  2. Ensure the Liberty Runtime is selected
  3. Click finish…

Your custom user feature should now be installed and ready to use. The last step is to include it within your server.xml, to do this:

  1. Click on the Servers tab (Window > Show View > Other and type Servers if it is not already open).
  2. Expand the liberty server and open the Server Configuration [server.xml] file.
  3. In the design view highlight the Feature Manager section.
  4. Click the Add button under Feature Manager Details and then type usr:.
  5. Click the usr:UserFeature and then OK
  6. Finally, save your configuration and start your liberty server
  7. confirm that the “Hello World!” message we created earlier outputs in the console.
  • obidul

    download & installation links mentioned in Prerequisites section doesn’t work.

    • Laura Cowen

      Hi obidul,

      Could you give it another go? The links seem to be working now. If you still have problems, could you let me know exactly what you see?

      Thanks

  • obidul

    I don’t see Liberty Feature Project wizard using WebSphere Application Server V8.5 Liberty Profile Developer Tools for Eclipse 3x.

    • Alasdair

      Hi, the Liberty Feature Project wizard is only available with the V8.5.5 tools for Juno, not the tools for Eclipse 3x.

  • Girdhar

    Error while installing feature .

    Could not install Liberty feature ‘testOwnCustomFeature’ on all selected runtime environments
    Error occurred while installing Liberty feature to runtime: WebSphere Application Server V8.5 Liberty Profile
    Failed to install feature: Process did not complete and had to be terminated