WebReference.com - Part 1 of Extending the JXTA Shell, from Early Adopter JXTA (Wrox Press). (1/3) | WebReference

WebReference.com - Part 1 of Extending the JXTA Shell, from Early Adopter JXTA (Wrox Press). (1/3)

current pageTo page 2To page 3
[next]

Early Adopter JXTA

Custom Commands to the Rescue

Custom commands enable advanced users to:

There are certainly many other possibilities. It should be obvious that the JXTA shell (and the code body that it encompasses) is much more than just a learning tool for JXTA newbies. Let's take a look at how we go about extending the shell and creating our own commands.

Basic Mechanism of Shell Extension

All of the shell's commands are part of the net.jxta.impl.shell.bin package. This includes commands such as peers, groups, search, etc. If you examine the source code of the JXTA shell (available freely at http://www.jxta.org), you will notice that they are all individual Java source files under their own package with the same name. For example, search.java is in the net.jxta.impl.shell.bin.search package.

During run time, the JXTA shell uses introspection to enumerate all of these commands and make them available to the user. Any time the user types in a command, these commands are re-scanned to check if an implementation is available.

To extend the JXTA shell, we simply add our own command implementation packages under net.jxta.impl.shell.bin.

Figure 6 reveals how the JXTA Shell can be extended with our own custom commands.

Diagram showing location of installed custom commands in the JXTA shell
Figure 6

In the diagram, we can see that our custom commands' classes must be "installed" into the net.jxta.impl.shell.bin package. This can be done in at least two different ways:

The second alternative is preferred, since it is directly supported by the shell itself, and does not require fiddling with the external Java VM's CLASSPATH. This makes it much less dependent on configuration and less prone to setup errors. Furthermore, it can be done at anytime after the JXTA shell has already started – and commands installed with instjar can be easily uninstalled using the uninstjar command. This means commands can be installed, tested, and uninstalled as part of their development process, without repeatedly launching the shell.

All that remains now is for us to actually write some custom command implementation code.


current pageTo page 2To page 3
[next]

Created: January 17, 2002
Revised: January 17, 2002


URL: http://webreference.com/programming/jxta/chap3/1/