An introduction to RAP

RAP (Rich Ajax Platform) is the framework that allows you to develop an RCP application an make it available over the network just pointing the browser to a given link.
In this article we will see how you can develop an RCP application and launch it both as a desktop as well as a web application. Yes, sure, exactly the same source code!
Don’t you believe it? Try it yourself.

 

Setup your IDE for RAP

The fastest way to get RAP working is downloading the Eclipse for RCP and RAP Developers package from page http://www.eclipse.org/downloads
´╗┐´╗┐´╗┐´╗┐´╗┐

Alternatively, you could add RAP from any other Eclipse Indigo SR2 (a.k.a. version 3.7.2) package, just going to Help -> Install New Software… -> select Indigo update site and install Rich Ajax Platform (RAP) Tooling 1.4.2 under the category Web, XML, Java EE and OSGi Enterprise Development.

Now we have to set up a RAP target plaftorm. Then start Eclipse and go to Window -> Preferences -> Plug-in Development -> Target Platform

and click Add… button and go Next

Give a name to the platform, e.g. RAP_1.4 and press Add… button in the first tab (Locations)

then select Software Site

and go Next. Then add the RAP 1.4 Runtime Update site
http://download.eclipse.org/rt/rap/1.4/runtime

uncheck that radio button Include required software and press Finish.

this may take quite a while. At the end that’s what you should see

click Finish.
Then follow the same procedure now adding, from Indigo update site http://download.eclipse.org/releases/indigo, the feature EMF RAP Target Components from Category EclipseRT Target Platform Components. You should now see the following

The important point here is that now you have two target platforms: the RCP and RAP ones. Select the RAP one for this workspace and press OK.

Now start another Eclipse instance and choose a different workspace, that will be used for RCP development.
Is it becoming clear what we are going to do? We want to have two different workspaces, one for running the RCP (=Desktop) launch and the other for running the RAP (=Web) launch. But what about the project? The very same source code!

After starting Eclipse with the RCP workspace follow one of the wizard for creating an RCP application: File -> New -> Plug-in Project, give the plug-in a name (e.g. it.rcpvision.rcprap.application) and select Yes at question “Do you want to create a Rich Client Application?“. Then choose the second template “RCP application with a view” and press Finish. Now launch the application; you will see the following

Up to now nothing special, just what you probably do almost every day.

Now let’s do a simple change in the Dependencies of this plug-in. Select the dependency from org.eclipse.ui and make it Optional.

Then go the tab MANIFEST.MF and add a dependency from org.eclipse.rap.ui and make it Optional too.

If you run again the application you’ll get, of course, the same result. We just introduced a double, optional, dependency to both RCP and RAP.

Now go back to the other Eclipse instance, the one pointing to the workspace configured for RAP, and import the same project from the file system.
Then select Run -> Run Configurations… -> RAP Application -> New

In the first tab (Main) click the Browse button for field Entry Point or Application

and select our application

In the second folder (Bundles) press Deselect All and add our application (it.rcpvision.rcprap.application) and the following plug-ins

com.ibm.icu.base
javax.servlet
org.eclipse.core.commands
org.eclipse.core.contenttype
org.eclipse.core.databinding
org.eclipse.core.databinding.beans
org.eclipse.core.databinding.observable
org.eclipse.core.databinding.property
org.eclipse.core.expressions
org.eclipse.core.jobs
org.eclipse.core.runtime
org.eclipse.equinox.app
org.eclipse.equinox.common
org.eclipse.equinox.http.jetty
org.eclipse.equinox.http.registry
org.eclipse.equinox.http.servlet
org.eclipse.equinox.http.servletbridge
org.eclipse.equinox.preferences
org.eclipse.equinox.registry
org.eclipse.equinox.servletbridge
org.eclipse.equinox.servletbridge.extensionbundle
org.eclipse.help
org.eclipse.jdt.junit.runtime
org.eclipse.osgi
org.eclipse.osgi.services
org.eclipse.rap.jface
org.eclipse.rap.jface.databinding
org.eclipse.rap.junit
org.eclipse.rap.junit.runtime
org.eclipse.rap.rwt
org.eclipse.rap.rwt.q07
org.eclipse.rap.rwt.theme.classic
org.eclipse.rap.ui
org.eclipse.rap.ui.cheatsheets
org.eclipse.rap.ui.forms
org.eclipse.rap.ui.views
org.eclipse.rap.ui.workbench
org.junit
org.mortbay.jetty.server
org.mortbay.jetty.util

Note: if you don’t want to add them one by one, you can persist the launch (tab Common -> Save as -> Shared file) then open the launch as text and change the following line

with this content

<stringAttribute key=”target_bundles” value=”com.ibm.icu.base@default:default,javax.servlet@default:default,org.eclipse.core.commands@default:default,org.eclipse.core.contenttype@default:default,org.eclipse.core.databinding.beans@default:default,org.eclipse.core.databinding.observable@default:default,org.eclipse.core.databinding.property@default:default,org.eclipse.core.databinding@default:default,org.eclipse.core.expressions@default:default,org.eclipse.core.jobs@default:default,org.eclipse.core.runtime@default:true,org.eclipse.equinox.app@default:default,org.eclipse.equinox.common@2:true,org.eclipse.equinox.http.jetty@default:default,org.eclipse.equinox.http.registry@default:default,org.eclipse.equinox.http.servlet@default:default,org.eclipse.equinox.http.servletbridge@default:default,org.eclipse.equinox.preferences@default:default,org.eclipse.equinox.registry@default:default,org.eclipse.equinox.servletbridge.extensionbundle@default:false,org.eclipse.equinox.servletbridge@default:default,org.eclipse.help@default:default,org.eclipse.jdt.junit.runtime@default:default,org.eclipse.osgi.services@default:default,org.eclipse.osgi@-1:true,org.eclipse.rap.jface.databinding@default:default,org.eclipse.rap.jface@default:default,org.eclipse.rap.junit.runtime@default:default,org.eclipse.rap.junit@default:default,org.eclipse.rap.rwt.q07@default:false,org.eclipse.rap.rwt.theme.classic@default:default,org.eclipse.rap.rwt@default:default,org.eclipse.rap.ui.cheatsheets@default:default,org.eclipse.rap.ui.forms@default:default,org.eclipse.rap.ui.views@default:default,org.eclipse.rap.ui.workbench@default:default,org.eclipse.rap.ui@default:default,org.junit@default:default,org.mortbay.jetty.server@default:default,org.mortbay.jetty.util@default:default”/>

Well, we are ready: run the launch and you’ll see the internal browser opening your application as a Web application!

You can now copy the same URL on your preferred browser from the same machine, but of course, you can also do the same from another machine, just replace the IP (127.0.0.1) with the one that identifies your machine on the network.

Happy RAP to everyone!

Acknowledgments
Thanks to the RAP Team and to Hendy Irawan for this article
http://eclipsedriven.blogspot.it/2010/12/eclipse-rap-single-sourcing-awesomeness.html, which inspired this tutorial.

 

 

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Application
Bundle-SymbolicName: it.rcpvision.rcprap.application; singleton:=true
Bundle-Version: 1.0.0.qualifier
Bundle-Activator: it.rcpvision.rcprap.application.Activator
Require-Bundle: org.eclipse.ui;resolution:=optional,
org.eclipse.rap.ui;resolution:=optional,
org.eclipse.core.runtime
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6