ICE Hello World Java

ICE Hello World Java

ZeroC ICE (Internet Communications Engine) is latest distributed computing platform which provides comprehensive Remote Procedure Calls (RPC) and supports Java, .NET, C++, Python, Objective-C, PHP, Ruby, and JavaScript. It’s getting famous day by day and big/small companies adapting in their service oriented architecture framework. Apart from RPC this framework also provides network infrastructure and many other features for technical application. As to start with it and understand how its RPC works, we will create simple Hello World program where we will run server and client separately.

Tools needed:

  • Eclipse any version
  • ICE jar (I am using Ice-3.5.1 which is latest as of today). Please download and install ICE using this tutorial and go to it’s lib folder (default location: C:\Program Files (x86)\ZeroC\Ice-3.5.1\lib) and include ICE.jar in your project.
  • JDK 1.6

Steps:

  • Create maven project name: ICEHelloWorld below is final project structure:

ICE Hello World Java

  • Create HelloWorld.ice inside src/main/resources folder and copy paste below code:

  • To work with ICE you will first have to create ICE file where you define all operations which you want to expose. As you see in the first line “module” it’s nothing but package name in ICE and inside you define your interface. Our module name is firstHelloWorld so when you generate code from this it will create package name “firstHelloWorld” and put all generated code inside it.

Now open your window command window and CD to location of ICE file and set class path for slice2java.exe as below:

ICE Hello World Java

  • To check if path has been set and you start using slice2java command to generate java file, please use below command you will see below:

ICE Hello World Java

  • Now to generate java file use below command:
    slice2java –output-dir C:\JavaHonk\workspace\ICEHelloWorld\src\main\java HelloWorld.ice

ICE Hello World Java

  • Go to your project and refresh it you will below package got created with all generate files:

ICE Hello World Java

  • Servent class: To implement HelloWorld interface, you will have to create servant class. By convention, servant classes use the name of their interface with an I‑suffix, so we will create servant class called HelloWorldI which will extend _HelloWorldDisp abstract class generate by sliece2Java command which internally implements interface HelloWorld where we had defined all operations. Copy paste below code:

HelloWorldI.Java:

  • Remote Server class: Create class Server.java inside package com.javahonk.server and copy paste below code:

  • Finally write client.java class which will make remote call and print its value:

  • Now we are ready to run our remote procedure client server call. First run Server.java as java application then run client.java class you will see below successful output:

Server console output:
ICE Hello World Java

Client console output:

ICE Hello World Java

  • That’s it for ICE Hello World Java application. For more information please visit ICE official tutorial here and here

download  Download Project:  ICEHelloWorld

Leave a Reply

Your email address will not be published. Required fields are marked *