Twitter Logo Follow us on Twitter
Project Information About this project

RWT standalone applications with RAP

It is possible to use RAP without OSGi. In that case RWT is used like normal Java library. It is recommended to use the RAP Tooling for developing RWT applications. Though it is not strictly necessary to use the tooling, it eases development with a launch configuration tailored for RWT applications and documentation.

Create and launch the application

Follow the steps outlined below and you will have a simple web application up and running in a few minutes.

  • Create a Java Project (or a Plug-in Project if you prefer, and are familiar with plug-in development)
  • Configure the project to match the layout of a web application. You may skip or postpone this step if you are using RAP Tooling to launch the application. The layout is necessary if you want to deploy the project as a WAR.
    • Create the three folders: WEB-INF, WEB-INF/lib, WEB-INF/classes
    • Change the projects' output folder to WEB-INF/classes.
  • Copy the org.eclipse.rap.rwt_* jar from the RAP Runtime into the WEB-INF/lib folder and add it to the projects' build path. The org.eclipse.rap.rwt.source_* jar contains the RWT source code. To be able to browse the sources and read JavaDoc, specify this jar as the Source Attachment
  • Implement an EntryPoint like below:
    public class HelloWorld extends AbstractEntryPoint {
      public void createContents( Composite parent ) {
        Label label = new Label( parent, SWT.NONE );
        label.setText( "Hello RAP World" );
      }
    }

With the RAP Tooling installed, you can already launch your HelloWorld application. To do so, select the HelloWorld class (i.e. in the Package Explorer) and choose Run As > RWT Application from the context menu.

Deploying

If you wish to deploy your application on an external servlet engine, or if you need a deployment descriptor for other reasons, or you haven't installed the RAP Tooling, a few more steps are required to run the application.

  • Place a deployment descriptor (web.xml) in the WEB-INF folder with the content below:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
      version="2.4">
    
      <context-param>
        <param-name>org.eclipse.rap.applicationConfiguration</param-name>
        <param-value>com.example.HelloWorldConfiguration</param-value>
      </context-param>
    
      <listener>
        <listener-class>org.eclipse.rap.rwt.engine.RWTServletContextListener</listener-class>
      </listener>
    
      <servlet>
        <servlet-name>rwtServlet</servlet-name>
        <servlet-class>org.eclipse.rap.rwt.engine.RWTServlet</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>rwtServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
      </servlet-mapping>
    </web-app> 
  • Provide an application configuration to configure your application like shown below:
    public class HelloWorldConfiguration implements ApplicationConfiguration {
      public void configure( Application application ) {
        application.addEntryPoint( "/hello", HelloWorld.class, null );
      }
    }
  • Again you can use the RAP Tooling to launch the application from the just created web.xml. To do so, create a new RWT Launch Configuration and select Run from web.xml. Enter the location of the web.xml file and specify hello as the servlet path.

You may also find the JFace components useful. In order to use them from RWT standalone, you will need to add the following jars from the RAP Runtime:

  • org.eclipse.rap.jface
  • org.eclipse.core.runtime
  • org.eclipse.core.commands
  • org.eclipse.equinox.common