Running a simple jini example


Since JINI is an old technology and if your code does not work, help that you get from the web can be little confusing (including mine :). JINI has changed to Apache River. There can be lots of disparity in articles between the old and the new versions. I hope Jini gets further development and more focus, because it is an amazing technology. If you are unfamiliar with JINI read this article. For this tutorial, I will be using the clock example from Jan Newmarch’s Guide to Jini Technologies. I hope this will help you explore more about JINI.


1. Download JINI 2.1 (or the Apache River). I will refer the directory where you downloaded and unzipped Jini as JINI_HOME. For this tutorial I will be using JINI 2.1. I will use Apache River in the near future, and if there is some inconsistency, I will add that to this tutorial.

I am using Linux (Windows should be fine) with OpenJDK 1.8.

Next, download Jan Newmarch’s codes either from his book’s website (Apress) or above link. Be sure to download the zip containing compiled files (containing jar archive), because we will be using his clock example jar files rather than trying to configure the ant file and compile everything.
2. Since there are many files inside JINI_HOME, and since that can be confusing, use a separate directory to host these files. Create a directory in your home directory called jini_examples. Create two directories inside jini_examples called lib and clock. Copy all the jars from inside JINI_HOME/lib directory to ~/jini_examples/lib directory.

In addition to the jar files, copy following files from JINI_HOME to the ~/jini_examples/lib directory.


Edit the lib/start-transient-reggie.config file and make the initial section look like this.

private static codebase = "http://localhost:8080/reggie-dl.jar";
private static policy = "/home/USERNAME/jini_examples/lib/reggie.policy";
private static classpath = "/home/USERNAME/jini_examples/lib/reggie.jar";
private static config = "/home/USERNAME/jini_examples/lib/transient-reggie.config";

Note: Change the USERNAME to your own username in Linux.

As you might have guessed from above lines, that we need more jar files. Inside JINI_HOME directory find reggie-dl.jar, and jsk-dl.jar and copy these jar files this time to the ~jini_examples/clock directory.

$ find | grep reggie-dl.jar

Finally, copy clock.clock.ticker.jar clock.clock-dl.jar from the build directory of Jan Newmarch’s example archive to the clock directory inside jini_examples. Since I will host the clock directory using a HTTP server, you only need the clock.clock-dl.jar inside the HTTP hosted server directory (if you are concerned about security). For simplicity I copied all the clock jars there.

3. Edit your .bashrc or .bash_profile file to include following lines


Note: You can omit the $PATH variable.

Execute the examples

We need to start few things before starting our example.

a. Http Server
b. RMI Activation daemon
c. RMI Registry or the JINI lookup service
d. Start the clock example

a. Http Server

We will use port 8080 for this example. You can use any http server to host these files. For the purpose of this tutorial we will use the one that came with JINI. Start the server using following commands.

$ cd ~/jini_examples
$ java -jar lib/tools.jar -port 8080 -dir clock/ -verbose

Here, tools.jar provides us the HTTP service. I started the server at 8080 port and hosted all the files inside the clock directory. I used -verbose option so that a message would show up in the console indicating the request that came from different services or clients when they download any file from this server.

reggie-dl.jar requested from localhost.localdomain:51265
reggie-dl.jar probed from localhost.localdomain:51289
reggie-dl.jar requested from localhost.localdomain:51290

Note: As mentioned above, if you don’t like clock.clock.ticker.jar and to be hosted from the HTTP directory, you can keep them somewhere else. These two files are not supposed to be hosted. I kept them inside, because I was lazy to create another directory and change the CLASSPATH. Only files that need to be hosted are reggie-dl.jar, jsk-dl.jar and clock.clock-dl.jar. The clock.clock-dl.jar is the proxy file for our clock service that the clients will download to adjust their time. Only the clock.clock-dl.jar is specific to this project.

b. RMI Activation daemon

To start the RMI Activation daemon run following command.

$ rmid &

The rmid service will run on background. You can check it using following command.

$ ps -ax | grep rmid
31975 ? Sl 0:07 rmid

RMI daemon is used by the lookup service called Reggie.

Note: You don’t need to start the rmid service twice, if it is already started. Use above command to check, if you need to start the rmid service or not.

c. RMI Registry or the JINI lookup service

I will escape the RMI Registry part, because I am only interested in JINI lookup service. If you want to read more about these steps, follow this article.

$ cd ~/jini_examples
// Don't use this command to start the lookup server (suggested by most tutorials. 
// It generates the error message "no main manifest attribute, in lib/reggie.jar"). 
// Use the next command instead.
// $ java -jar lib/reggie.jar http://localhost:8080/reggie-dl.jar lib/jsk-all.policy /tmp/reggie_log public
$ java -jar lib/start.jar lib/start-transient-reggie.config

After executing the above command (the second one), your http server should display something like this

reggie-dl.jar requested from localhost.localdomain:51505

The lookup server should start with java.lang.ClassNotFoundException:com.sun.jini.reggie.RegistrarProxy warning message. One post suggested to use “-Djava.rmi.server.useCodebaseOnly=false” option, but it did not work. For this example it should be fine.

d. Start the clock example

I created two scripts to run the two clock jar files (inside the ~/jini_examples/clock directory).

java -Djava.rmi.server.codebase=http://localhost:8080/clock.clock-dl.jar clock.clock.TickerClock "Ticking Clock"
java -Djava.rmi.server.codebase=http://localhost:8080/clock.clock-dl.jar clock.clock.ComputerClock "Computer Clock"

Note: Again change USERNAME to your own username in Linux.

Run 2 or 3 instances of the in separate terminals. Once those start, run the

# All in separate terminals, all commands from inside the ~/jini_examples/clock directory

$ ./ 
$ ./
$ ./

You should see the dumb clocks flashing and showing wrong time. This is deliberate. When you start the, it should fix the time and the dumb clocks should stop flashing. The purpose of the smart clock is to fix the dumb clocks using JINI.


Your HTTP server log should be something like this

Nov 09, 2014 11:16:45 PM com.sun.jini.tool.ClassServer run
INFO: ClassServer started [[clock/], port 8080]
reggie-dl.jar requested from localhost.localdomain:51505
reggie-dl.jar probed from localhost.localdomain:51511
reggie-dl.jar requested from localhost.localdomain:51512
reggie-dl.jar probed from localhost.localdomain:51514
reggie-dl.jar requested from localhost.localdomain:51515
reggie-dl.jar probed from localhost.localdomain:51556
reggie-dl.jar requested from localhost.localdomain:51557


This tutorial should get you started using Jini. Cheers !!


Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s