public interface HelloService {
String sayHello(String name);
}
public class HelloServiceImpl implements HelloService {
@Override
public String sayHello(String name) {
return "Hello, " + name + "!";
}
}
public class Server {
public static void main(String[] args) throws Exception {
HelloService helloService = new HelloServiceImpl();
JNDIRegistry registry = new JNDIRegistry();
registry.rebind("HelloService", helloService);
ServerConnection server = new ServerConnection(registry);
server.start();
}
}
public class Client {
public static void main(String[] args) throws Exception {
InitialContext context = new InitialContext();
HelloService helloService = (HelloService) context.lookup("HelloService");
String response = helloService.sayHello("Alice");
System.out.println(response);
}
}
<dependencies>
<dependency>
<groupId>org.jboss.remoting</groupId>
<artifactId>jboss-remoting</artifactId>
<version>3.0.0.Final</version>
</dependency>
</dependencies>
JNDIRegistry registry = new JNDIRegistry();
InitialContext context = new InitialContext();