Xj3D in Eclipse RCP

With the Xj3D 2.0 development releases, support for embedding the Xj3D browser in Eclipse RCP applications is available. The following will walk you through the steps to begin using Xj3D from the Eclipse development environment.


Before beginning, several software packages are required.

Configuring Eclipse

To get started, the development environment requires some configuration. Begin by starting the Eclipse IDE.

Target Platform

The first configuration step is to set the target platform to the working directory where the target plugins are installed. From the main Eclipse window, select Window > Preferences to open the Preferences dialog. On the Preferences dialog, select the Plug-in Development > Target Platform page and use the Browse function to choose the target platform directory [C:/Java/Eclipse_RCP_Target/eclipse]. Select the Reload button and you will see that the set of plugins matches those that have been downloaded and installed. You can now close this dialog by selecting the OK button.

Import Examples

Now that the target platform has been configured, you can import the Xj3D example projects. From the main Eclipse window select File > Import to open the Import dialog. On the Import dialog select General > Existing Projects into Workspace and then select the Next > button to proceed to the Import Projects dialog.

From the Import Projects dialog, use the Browse function to locate and select the Xj3D example projects. The projects will be imported into your workspace when you select the Finish button.

Xj3D Browser Projects

After the import is complete, you will have two new projects in the Eclipse SDK Package Explorer. These examples are functional as they are installed. They may be used as a starting place for embedding an Xj3D browser configured to your own preferences.

The projects are shown here expanded to display the source files. The following two sections review the classes from the project where the browser instances are specified - and notes the requirements specific to Xj3D.


This project implements the Xj3D Browser View in a default configuration with it's full complement of toolbars and controls in a standalone application. The View is instantiated in the class Perspective.java.


  package org.xj3d.browser.app;

  import org.eclipse.ui.IPageLayout;
  import org.eclipse.ui.IPerspectiveFactory;

  import org.xj3d.ui.swt.view.BrowserViewConstants;

  public class Perspective implements IPerspectiveFactory {

    public void createInitialLayout(IPageLayout layout) {
      String editorArea = layout.getEditorArea();

Adding the View by referencing it's ID.

      false, IPageLayout.LEFT, 1.0f, editorArea);


This project implements an SAI Xj3D Browser in a standalone application. The browser is instantiated in the class View.java. Several necessary configuration steps are annotated in the following slices of code from the class.


  package org.xj3d.browser.sai_app;
  public class View extends ViewPart implements DisposeListener {
    public void createPartControl(Composite parent) {
      parent.setLayout( new FillLayout( ) );
      parent.addDisposeListener( this );

The configuration parameters for creating the X3DComponent. The parameter Xj3D_SWT_Parent_Composite is required. The parameter Xj3D_Eclipse_View is optional, but desirable to include as this allows the browser to 'throttle' back it's CPU usage when the browser View is not visible in the application. All other parameters are optional and are documented in the factory impl class javadoc. (org.xj3d.ui.swt.browser.ogl.X3DSWTOGLBrowserFactoryImpl)

The remaining parameters used: Xj3D_NavbarShown and Xj3D_LocationShown disable the navigation and location toolbars.

      HashMap params = new HashMap( );
      // hard coded defaults for now....
      params.put( "Xj3D_SWT_Parent_Composite", parent );
      params.put( "Xj3D_Eclipse_View", this );
      params.put( "Xj3D_NavbarShown", Boolean.FALSE );
      params.put( "Xj3D_LocationShown", Boolean.FALSE );

The System property x3d.sai.factory.class MUST be initialized to the correct value in order for the BrowserFactory to instantiate and return an SWT Composite subclass.

      System.setProperty( "x3d.sai.factory.class",
        "org.xj3d.ui.swt.browser.ogl.X3DSWTOGLBrowserFactoryImpl" );
      x3dComponent = BrowserFactory.createX3DComponent( params );
      browser = x3dComponent.getBrowser( );


The projects will Run as they are. The projects may also be exported as standalone products. The following shows the sequence of steps to export.

From the main Eclipse window select File > Export to open the Export dialog. On the Export dialog select Plug-in Development > Eclipse Product and then select the Next > button to proceed to the Export Eclipse Product dialog.

From the Export Eclipse Product dialog, use the Browse function to select a destination directory. In this example, the directory C:/Java/Xj3D/app has been selected. The Eclipse RCP product will be exported into your specified destination directory when you select the Finish button.