home *** CD-ROM | disk | FTP | other *** search
/ Internet News 1999 October / INEWS_10_CD.ISO / pc / jdk / jdk1.2.2 / docs / guide / rmi / examples / stock / run < prev    next >
Encoding:
Text File  |  1999-09-19  |  3.3 KB  |  177 lines

  1. #!/bin/sh -e
  2.  
  3. #
  4. # Note to readers: This shell script is more complicated than simply
  5. # running the commands because it must handle many error conditions,
  6. # especially those that first time users are likely to encounter.
  7. # The meat of the script is down below the functions, where the first
  8. # "show" command is issued (that is, the first line that starts with
  9. # "show").  If you simply want to see what's done, read the
  10. # documentation.  The important commands are (assuming that ../.. is
  11. # in your CLASSPATH):
  12. #
  13. #    javac -d ../.. *.java
  14. #    rmic -d ../.. examples.stock.StockServer examples.stock.StockApplet
  15. #    java -Djava.security.policy=security.policy examples.stock.StockServer &
  16. #    appletviewer index.html
  17. #
  18. # So if you're looking for information on how to run things yourself,
  19. # just ignore the entire script and use the above commands.
  20. #
  21.  
  22. #
  23. # the directories in the path
  24. #
  25. pathdirs=`echo $PATH | tr ':' ' '`
  26.  
  27. #
  28. # find a binary somewhere in the path
  29. #
  30. findbin()
  31. {
  32.     prog=$1;
  33.     for dir in $pathdirs; do
  34.     if [ -x $dir/$prog ]; then
  35.         echo $dir/$prog
  36.         return;
  37.     fi
  38.     done
  39.     echo "Cannot find $prog in your path--please check your PATH variable" 1>&2
  40.     exit 1
  41. }
  42.  
  43. #
  44. # run a command, showing it (if -v is given, only in verbose mode)
  45. #
  46. run()
  47. {
  48.     if [ x"$1" = "x-v" ]; then
  49.     show "$@"
  50.     shift
  51.     else
  52.     show % "$@"
  53.     fi
  54.     eval "$@" || (
  55.     echo Running "$@" 1>&2
  56.     exit 2
  57.     )
  58. }
  59.  
  60. #
  61. # show some string (if -v, only in verbose)
  62. #
  63. show()
  64. {
  65.     if [ x"$1" = x"-v" ]; then
  66.     if [ "$verbose" != "" ]; then
  67.         shift
  68.         echo "..." "$@"
  69.     fi
  70.     elif [ x"$1" = x"-c" ]; then
  71.     shift
  72.     echo ""
  73.     echo "$@"
  74.     else
  75.     echo "$@"
  76.     fi
  77. }
  78.  
  79. #
  80. # kill off all processes
  81. #
  82. killpids() {
  83.     kill 0
  84. }
  85.  
  86. #
  87. # Process options
  88. #
  89. set +e
  90. while getopts vc opt; do
  91.     case $opt in
  92.       v) verbose="yes";;
  93.       c)
  94.     show -v cleaning out old stuff
  95.     rm -rf */. *.class core;;
  96.       \?)
  97.     echo "usage: run [-v] [-c]"
  98.     echo "   -c: clean before running"
  99.     echo "   -v: verbose"
  100.     exit 1
  101.     ;;
  102.     esac
  103. done
  104. shift `expr $OPTIND - 1`
  105. set -e
  106.  
  107. #
  108. # Ensure that these programs can be found
  109. #
  110. javac=`findbin javac`
  111. rmic=`findbin rmic`
  112. show -v "javac is $javac"
  113. show -v "rmic is $rmic"
  114.  
  115. #
  116. # (There is no need to run rmiregistry for this example since
  117. # the StockServer class bundles its own registry.)
  118. #
  119.  
  120. # The top of the package
  121. top=../..
  122.  
  123. show -v origCLASSPATH=$CLASSPATH
  124. origCLASSPATH=$CLASSPATH
  125. export CLASSPATH
  126.  
  127. case "$CLASSPATH" in
  128.     "")
  129.     CLASSPATH=$top
  130.     ;;
  131.     $top:* | *:$top:* )
  132.     ;;
  133.     *)
  134.     CLASSPATH="$top:$CLASSPATH"
  135.     ;;
  136. esac
  137.  
  138. show -v "CLASSPATH=$CLASSPATH"
  139.  
  140. #
  141. # Compile the source
  142. #
  143. show -c "Compiling Java sources"
  144. run javac -d $top *.java
  145.  
  146. #
  147. # Run rmic
  148. #
  149. server=examples.stock.StockServer
  150. applet=examples.stock.StockApplet
  151. show -c "Running rmic on the implementations"
  152. run rmic -d $top $server $applet
  153.  
  154. #
  155. # Set up traps so that interrupt kills things off
  156. #
  157. trap killpids INT EXIT
  158.  
  159. #
  160. # Running the server
  161. #
  162. show -c "Start server $server"
  163. run java -Djava.security.policy=security.policy $server &
  164.  
  165. # sleep to give the server time to start up and print its message
  166. run -v sleep 6
  167.  
  168. #
  169. # Run the appletviewer, after setting the class path back to the original
  170. # so that class loading is done via the codebase, not the class path.
  171. #
  172. show -v CLASSPATH=$origCLASSPATH
  173. CLASSPATH=$origCLASSPATH
  174.  
  175. show -c "Starting the appletviewer"
  176. run appletviewer index.html
  177.