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.
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:- Click File > New > Project ....
- Expand WebSphere sMash category folder near the bottom and click the WebSphere sMash Application project type.
- Click Next >.
- Enter a name for your new application and click Finish to create it. Your new project is shown with a distinctive icon beside it.
- 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'sconfig/zero.configfile. - Open a browser and enter
http://localhost:8080/to see the default page of your application. It should look something like this:
- Stop your application.
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
/libdirectory to yourclasspath. - Resolved Libraries
- Resolves libraries from configured repositories and adds them to your
classpath. This container uses anivy.xmlfile located in theconfigdirectory to resolve dependencies from repositories and adds the resolved JAR and ZIP files to yourclasspath.
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:
- Stop your application if it is currently running. Applications should be stopped before modifying their configuration.
- Double-click the config/ivy.xml file in your
project to open Dependencies Editor as shown below:
- 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:
- 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:
- 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.
- 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.
- Click Ctrl-S or File > Save to save the modified package information.
- To see the zero.data library added to your
classpathas shown below, expand the Resolved Libraries container in your project tree.
- 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
/libdirectory of your project. This triggers the Local Libraries container to refresh and add the library to yourclasspath. 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.
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.- If the Expressions view is not already open, show it using Window > Show View.
- Click the view toolbar button that has the tooltip "Create a new watch expression".
- Enter an expression like the following one and press OK.
GlobalContext.zget("/config/root"); - 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.
- Click File->New->Example....
- If you have multiple Example types, expand WebSphere sMash Examples.
- Select WebSphere sMash Example Projects and click Next >.
- 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:- Right-click the project and click Export....
- Expand the WebSphere sMash category.
- Select WebSphere sMash Export Wizard and click Next.
- Click Browse... to select a directory and store the exported zip file.
- Check Include Source to include the source project.
- Click Finish to export the project.
Importing applications
To import a WebSphere sMash application that has the source included (see above), complete the following steps:- Click File > Import > General > Existing Projects into Workspace.
- Click Next.
- Select the Select Archive File radio button.
- Select Browse... to locate your exported WebSphere sMash zip file (for a project that is not already in your workspace) and click OK.
- Click Finish to import the checked project.