WebReference.com - Part 1 of Extending the JXTA Shell, from Early Adopter JXTA (Wrox Press). (3/3)
[previous] |
Early Adopter JXTA
Compiling the Custom Command and Creating the JAR File
You will find the source code to the date
command under the src
directory of the distribution. We have also supplied a batch file (for Win32 systems) to compile
the code and create a JAR file with it. The file is called makedate.bat
and contains:
set SHELLROOT=..
javac -classpath %SHELLROOT%\lib\jxta.jar;%SHELLROOT%\lib\jxtashell.jar -d %SHELLROOT%\classes net\jxta\impl\shell\bin\date\*.java
cd ..\classes
jar cvf ..\custcmds\datecmd.jar net\jxta\impl\shell\bin\date\date.class
cd ..\src
This will create a datecmd.jar
file, containing the custom command, and place
it into the custcmds
directory of the distribution.
Run this makedate.bat
file from the src
directory to compile
the code and create the required JAR file.
Installing the Custom date Command
The datecmd.jar
file contains our customized date
command, and
is a very convenient packaging for delivering or sharing custom shell commands that we create. Anyone
who gets a copy of the datecmd.jar
file can also use our date command.
To install the JAR file into an instance of a JXTA shell, first start a JXTA shell from
the custcmds
directory of the distribution. Use the runshell.bat
command to
do this. Then configure the shell to run locally, and at the command line install the JAR file using:
JXTA> instjar datecmd.jar
Testing the Custom date Command
We can finally try out this custom command:
JXTA> date
Nov 11, 2002 12:30 am
You can also try the help function:
JXTA> man date
NAME
date - get the current date and time
SYNOPSIS
date
DESCRIPTION
'date' prints the current date and time to stdout.
EXAMPLE
JXTA>date
We see here that the custom command appears to be every bit as "native" as one of the built-in commands. Since they share exactly the same mechanism of construction and deployment, there is little observable difference.
Uninstalling the Custom date Command
If you are using many different sets of custom commands for different reasons (testing of new services, etc), it is convenient to be able to load and unload them in order to keep the command namespace uncluttered (to avoid having multiple commands with the same name). This can be done be uninstalling any command JAR file that may be installed.
To uninstall a JAR file, first find out its installation ordinal number using:
JXTA> instjar
Then use the command uninstjar
and the -i
switch to remove it:
JXTA> uninstjar Âi 0
Now the date command is no longer available.
As a final example in this chapter, we will create a significantly more involved shell command, one that will be quite useful in our daily experimentation and work with the JXTA shell. [To be continued in part 2 - Ed.]
[previous] |
Created: January 17, 2002
Revised: January 17, 2002
URL: https://webreference.com/programming/jxta/chap3/1/3.html