Plug-in for Java and Groovy

This article provides information about installing and configuring IBM® WebSphere® sMash Java™/Groovy plug-in for Eclipse.

Eclipse is a Java-based development platform developed by an open community. It includes extensible frameworks and tools for building and managing software throughout its life cycle.

Prerequisites

If you choose to develop with Eclipse, the following prerequisites are required:

  • Windows®, Linux®, or Mac operating system
  • Java SE Development Kit (JDK) 5.0 or 6.0

    IBM employees should download the Java SDK from the IBM internal site.

  • Eclipse IDE for Java Developers

    Eclipse must be started with version 5.0 (or later) of the JDK or download errors occur.

Installation

Use the following update site to install the WebSphere sMash Java/Groovy plug-in.

https://www.projectzero.org/zero/silverstone/latest/update/zero.eclipse

If you need assistance with this step, open the Eclipse Help browser (Help > Help Contents) and search for the term install.

Creating and running an application

To create and then run a WebSphere sMash application, complete the following steps:

  1. Click File > New > Project ....
  2. Expand WebSphere sMash category folder near the bottom and click the WebSphere sMash Application project type.
  3. Click Next >.
  4. Enter a name for your new application and click Finish to create it. Your new project is shown with a distinctive icon beside it.
  5. To run your new application, right-click the project and click Run As > WebSphere sMash Application. A message is displayed in the console indicating that the application was started on port 8080.

    Note: All applications use port 8080 by default. If you have another application started, it cannot use the same port. The port is configured in the application's config/zero.config file.
  6. Open a browser and enter http://localhost:8080/ to see the default page of your application. It should look something like this:

    Default application page
  7. Stop your application.

Congratulations! You have created and run your first WebSphere sMash application. Continue reading to find out how you can add additional dependencies to enhance your application. You can also look at the Employee Demo or Suggest Demo for coding examples.

Adding dependencies

WebSphere sMash uses a dependency management utility called Ivy to ensure that your application is using the right versions of the libraries you declare as dependencies. In Ivy, these libraries are called modules, and they are located through a process called dependency resolution. See the documentation on Dependency Management for more information.

In your project tree there are three classpath containers. One is a JRE container provided by the Eclipse Java tooling. The other two are WebSphere sMash library containers. The WebSphere sMash library containers are:

Local Libraries
Adds all of the JAR and ZIP files from the /lib directory to your classpath .
Resolved Libraries
Resolves libraries from configured repositories and adds them to your classpath . This container uses an ivy.xml file located in the config directory to resolve dependencies from repositories and adds the resolved JAR and ZIP files to your classpath .

You can add JAR files to the project classpath by copying them into the lib directory of the project, or by adding dependencies from repositories. When a project is first created, it has one dependency: zero.core.

You can add dependencies to your project from the local repository. The following steps show how this is done by editing the dependency configuration to add the zero.data library to the project:

  1. Stop your application if it is currently running. Applications should be stopped before modifying their configuration.
  2. Double-click the config/ivy.xml file in your project to open Dependencies Editor as shown below:

    Dependencies Editor
  3. Click the Add... button in the Dependencies section of the editor. The Dependency Selection dialog that displays allows you to select a dependency from the local repository which was installed with the Eclipse plug-in as shown below:

    Dependency Selection dialog
  4. If your local repository does not already contain the dependency that you need, as is the case here, click the Manage Repository button to find the dependency in a remote repository. This opens a new dialog like the following example:

    Manage Repository dialog
  5. Enter zero.data in the Module field and click Search to find the zero.data library. After finding it, select it and click Download to add the zero.data library to your local repository and click Close to exit the Manage Repository dialog.
  6. Now, from the Dependency Selection dialog select zero:zero.data(1.0+) from the list and click OK. The dependency has been added to the list.
  7. Click Ctrl-S or File > Save to save the modified package information.
  8. To see the zero.data library added to your classpath as shown below, expand the Resolved Libraries container in your project tree.

    zero.data dependency added
  9. If the library is not currently located in a repository, then you can add a library to the Local Libraries container. To do this, drag and drop a JAR file into the /lib directory of your project. This triggers the Local Libraries container to refresh and add the library to your classpath . You can expand the Local Libraries container to see the JAR file.

Debugging

Start debugging your application by right-clicking your application folder and selecting Debug as > WebSphere sMash Application. After you see a message in the console indicating that your application is started, you can use your browser to fire a request.

In the example below a breakpoint was set in the target script, so the state of the GlobalContext during the request processing can be inspected. The structure of the GlobalContext can be difficult to inspect in the default Variables view. So, the WebSphere sMash plug-in provides a specialized debug view for the GlobalContext that presents the content as a tree.

GlobalContext debug view

This view is usually shown by default when debugging Groovy or Java source files. If it is not, then you can click Window > Show View > Other > Debug > GlobalContext.

The Expressions view

The Expressions view in the Debug perspective is an alternative way to retrieve GlobalContext state during debugging. After you hit a breakpoint in a Java file, you may retrieve a value from the GlobalContext by following these instructions.

  1. If the Expressions view is not already open, show it using Window > Show View.
  2. Click the view toolbar button that has the tooltip "Create a new watch expression".
  3. Enter an expression like the following one and press OK.
    GlobalContext.zget("/config/root");
  4. The expression will be added to the Expressions view. When you click it, you will see the value of the expression in another part of the view. For this example, the value is the path to the application root.

Using WebSphere sMash examples

If you installed all of the plug-ins (including the samples plug-in) from WebSphere sMash site, you can create example WebSphere sMash projects in your workspace.

  1. Click File->New->Example....
  2. If you have multiple Example types, expand WebSphere sMash Examples.
  3. Select WebSphere sMash Example Projects and click Next >.
  4. Choose one or more examples to create as projects in your Workspace and click Finish.

See the Employee Demo and Suggest Demo documentation for more example code.

Exporting applications

To export your application, complete the following steps:

  1. Right-click the project and click Export....
  2. Expand the WebSphere sMash category.
  3. Select WebSphere sMash Export Wizard and click Next.
  4. Click Browse... to select a directory and store the exported zip file.
  5. Check Include Source to include the source project.
  6. Click Finish to export the project.
Note: you must include source if you plan to import the project back into Eclipse.

Importing applications

To import a WebSphere sMash application that has the source included (see above), complete the following steps:

  1. Click File > Import > General > Existing Projects into Workspace.
  2. Click Next.
  3. Select the Select Archive File radio button.
  4. Select Browse... to locate your exported WebSphere sMash zip file (for a project that is not already in your workspace) and click OK.
  5. Click Finish to import the checked project.

Version 1.1.26825