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 stricly 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 if you 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 neccessary 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 IEntryPoint like below:
    public class HelloWorld implements IEntryPoint {
      public int createUI() {
        Display display = new Display();
        Shell shell = new Shell( display );
        shell.setLayout( new GridLayout() );
        Label label = new Label( shell, SWT.NONE );
        label.setText( "Hello RAP World" );
        shell.setSize( 500, 400 );
        shell.open();
        return 0;
      }
    }

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 whish to deploy your application on an external servlet engine, or if you need a deployment descriptor for other reasons, or if 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.rwt.engine.RWTServletContextListener</listener-class>
      </listener>
    
      <servlet>
        <servlet-name>rwtServlet</servlet-name>
        <servlet-class>org.eclipse.rwt.engine.RWTServlet</servlet-class>
      </servlet>
    
      <servlet-mapping>
        <servlet-name>rwtServlet</servlet-name>
        <url-pattern>/hello</url-pattern>
      </servlet-mapping>
    </web-app> 
  • Provide an implementation of ApplicationConfigurator 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