Project Documentation

Built by Maven

Basic Usage

Files used in these examples are located under the src/example directory. S2RMI makes components registered in the S2Container into remote objects. service.Hello interface is a normal interface. Furthermore, service.impl.HelloImpl class is an implementation class (POJO) of Hello interface. Remote objects are released by S2RMI using Hello interface and its implementation class.



public interface Hello {
    public String say();


public class HelloImpl implements Hello {
    public String say() {
        return "Hello";

Server Settings

Following 3 components must be defined in a dicon file on a server.

  • org.seasar.remoting.rmi.adaptor.RMIAdaptorImpl
  • org.seasar.remoting.rmi.deployer.RMIAdaptorDeployer
  • service.impl.HelloImpl (implementation class of interface of remote object to be released)

RMIAdaptorImpl class is an adapter that uses ComponentInvokerImpl class to call component registered in the S2Container. RMIAdaptorDeployer registers RMIAdaptorImpl class into RMI registry.


  <component name="rmiAdapptor" class="org.seasar.remoting.rmi.adaptor.RMIAdaptorImpl">
    <property name="invoker">
      <component class="org.seasar.extension.component.impl.ComponentInvokerImpl"/>

  <component class="org.seasar.remoting.rmi.deployer.RMIAdaptorDeployer">
    <property name="adaptor">rmiAdapptor</property>
    <property name="registryPort">1108</property>
    <property name="servicePort">1109</property>
    <initMethod name="deploy"/>

  <component name="hello" class="service.impl.HelloImpl"/>

RMIAdaptorDeployer property

<property name="registryPort">
Port number of rmiregistry. When omitted, default port (1099) is used.
<property name="servicePort">
Port number to be used by RMIAdaptorImpl. When omitted, port is set to the default port (0) and anonymous port is used.

Starting RMIAdaptorDeployer

A component in S2Container can be called remotely by initializing the S2Container. S2Container is initialized by defining <initMethod name="deploy"/> in the dicon file.


package server;

import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import org.seasar.remoting.common.deployer.Deployer;

public class ServerMain {
    public static void main(String[] args) {

To execute ServerMain, right click on ServerMain.java in the package explorer and select [Execute]-[Java Application].

Client Settings

Following 3 components must be defined in a dicon file on a client.

  • org.seasar.remoting.rmi.connector.RMIConnector
  • org.seasar.remoting.common.interceptor.RemotingInterceptor
  • service.Hello (interface to call on a remote object)

RMIConnector call retrieves RMIAdaptorImpl class from RMI registry and calls a component on the server. RemotingInterceptor class uses RMIConnector to set by AOP an interface (Hello) to call on remote object. Name of remote object to call and name of component to be called (hello) must be the same.

S2RMI is an implementation of S2Remoting. Therefore, it is possible to switch so remote object are called using S2Axis just be changing connector setting in RemotingInterceptor from RMIConnector to org.seasar.remoting.axis.connector.AxisConnector. Refer to Setting S2Axis Server for information on using S2Axis.


  <component name="rmiConnector" class="org.seasar.remoting.rmi.connector.RMIConnector">
    <property name="baseURLAsString">"rmi://localhost:1108/"</propert>
    <initMethod name="lookup"/>

  <component name="remoting"
    <property name="connector">rmiConnector</property>

  <component name="hello" class="service.Hello">

Calling Remote Object

When a method in interface which is defined as AOP to RemoteingInterceptor on the client is called, following tasks are executed:

Hello.say() -> RMIConnector -> RMIAdaptor -> ComponentInvoker -> HelloImpl.say()

Following ClientMain is an example of executable class on a client.


package client;

import org.seasar.framework.container.S2Container;
import org.seasar.framework.container.factory.S2ContainerFactory;
import service.Hello;

public class ClientMain {
    public static void main(String[] args) {
        S2Container container = S2ContainerFactory
        Hello hello = (Hello) container


To execute ClientMain, right click on ClientMain.java in the package explorer and select [Execute]-[Java Application].