By Daniel Brookshier
This is a quick guide to building and running the code from the book. In general these instructions apply to building JXTA code in general. Check http://people.jxta.org/turbogeek/ for the latest copy of the book code for the current release of the JXTA platform.
The fist thing to do is unzip the code directories and the lib zip file. The lib.zip file has all the jar files to build the code. Note that you can get newer jar files from the jxta.org projects, but these are guarnteed to work with the current version of the code. First, unzip everything into a single directory. In this example, we created a directory called JXTA_Book.
The next thing you need to do is mount a filesystem in NetBeans (remember this works for Forte's too). Mounting a filesystem really just means you are making a directory tree visible. Here is our tree. We have clicked on ch5_ping, to open the directory. We have also clicked on Ping_ch5 which is an XML ANT file. ANT is a cool tool that lets you do the kinds of things you need for building and executing software. NetBeans supports ANT by overlaying a GUI that lets you build and manipulate ANT. If you want to see the raw XML in the ant file, right click over the file and select 'open' from the popup menu.
In the remainder of this example, we will show how to run the ping example from chapter 5.
The source files are under each chapter directory in a directory called source. The files are in their apropriate package directory.
The next thing to do is build the file. To do this, simply double click on the arrow next to the compile tag in the ANT file. This will compile everything in the source directory. The class files will be placed in the classes directory. Because ANT works like make, if required, the init command is also executed. Our init creates a few directories like the dist and classes directories.
Once you have a clean compile, you can now run the application. Depending on what chapter and example you are working with, you will see different tags for running the example. For ping, there is PingDemo1 through PingDemo3. Note that we did not click on the jar tag. In ANT, the jar tag is automatically executed if required. In fact, if you change the code and then doule click on the example's run tag, the code will be compiled. jar'd and then executed if no errors were found.
The run tag, like any exacutable tag in ANT, acts like a script. If you open up PingDemo2 tag, you will see three entries: delete, touch, and java.
Details of the ANT Commands
If you double click on the commands, you will see a property editor that can be used to configure the command. We show the property editors for the commands in PindDemo2. The delete caused the test2/cm directory to be deleted. The touch causes a file called test\reconf to be created. The java tag runs the application in the test2 directory. Note also that the java command uses a classpath reference. Some of our exaples have the classpath in the command and some use tags. It is probably better to use the reference tags and we will convert them soon.
If you select the button in the path property you will see the jar files that are referenced.
Because many of the examples in our book require multiple running versions, you will either need two computers or run the applications on the same machine. Unfortunatly running two copies of JXTA on a single machine is a little messy, but not hard. To start, run ShellDemo1 in ANT by double clicking the arrow to the left of the tag name. This will launch JXTA and display the configuration box. Note that the touch command can be used to create a file called reconf (note that there is no extension). If the reconf file is found in the execution directory, JXTA will display the dialog. Note that ShellDemo2 will always display the dialog.
Another thing that is important is the execution diectory. Each of our examples, runs the client in a different directory. Never start a client twice because you will get an error. A JXTA client uses its runtime directory to store files and two clients cannot share any of these files. For our first client the directory is test1. Note that ANT created this directory in the init tag.
When the dialog apears, name this peer Client1.
The next thing to do press the advanced button. This screen is used to specify what ports are used. For client one we use 9711, and 9710. Remember to change 'all' the port numbers.
Next press the security button and enter an ID and password used for encryption. Select the ok button when you are finished and the client will start. In this case, the standard JXTA Shell application will be run.
Now double click the arrow to the left of the PingDemo2 tag. When the configuration dialog launches, use client2 as the name of the peer.
Select the advanced button and use the port numbers 9721 and 9720.
Select the security button and enter the id and password as before (note that you can use the same ID and password if you want).
Now that the clients are properly configured, we can now test the shell command that we wrote in chapter 5. In the second shell (the peer named client2), type ping -listen. Just to be sure we are in the right shell you can also type whoami as we have done here.
In the shell opened for client1, we type ping client2. The ping command will execute and return the ping times. Note that in the shell for client2, the display will print a status message that it was pinged by client1.
That's all there is to it. Most of the ANT files for the book examples are similar. Your best bet for help is to search the message lists on jxta.org. The best one is the user list at: http://www.jxta.org/servlets/SearchList?listName=user&by=thread.
Have fun!
Daniel Brookshier