home *** CD-ROM | disk | FTP | other *** search
/ BUG 15 / BUGCD1998_06.ISO / aplic / jbuilder / jhelp.z / run < prev    next >
Text File  |  1997-07-30  |  4KB  |  182 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:
  11. #
  12. #    rmiregistry &
  13. #    javac -d ../.. *.java
  14. #    rmic -d ../.. examples.hello.HelloImpl
  15. #    java -Djava.rmi.server.codebase="your_url" examples.hello.HelloImpl &
  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. rmiregistry=`findbin rmiregistry`
  113. show -v "javac is $javac"
  114. show -v "rmic is $rmic"
  115. show -v "rmiregistry is $rmiregistry"
  116.  
  117. #
  118. # Set up traps so that interrupt kills things off
  119. #
  120. trap killpids INT EXIT
  121.  
  122. #
  123. # Running the registry
  124. #
  125. show -c "Run registry"
  126. run rmiregistry &
  127.  
  128. # The top of the package
  129. top=../..
  130.  
  131. show -v origCLASSPATH=$CLASSPATH
  132. origCLASSPATH=$CLASSPATH
  133. export CLASSPATH
  134.  
  135. case "$CLASSPATH" in
  136.     "")
  137.     CLASSPATH=$top
  138.     ;;
  139.     $top:* | *:$top:* )
  140.     ;;
  141.     *)
  142.     CLASSPATH="$top:$CLASSPATH"
  143.     ;;
  144. esac
  145.  
  146. show -v "CLASSPATH=$CLASSPATH"
  147.  
  148. abstop=`dirname \`dirname $PWD\``
  149. codebase_url="file:$abstop/"
  150.  
  151. #
  152. # Compile the source
  153. #
  154. show -c "Compiling Java sources"
  155. run javac -d $top *.java
  156.  
  157. #
  158. # Run rmic
  159. #
  160. server=examples.hello.HelloImpl
  161. show -c "Running rmic on the implementations"
  162. run rmic -d $top $server
  163.  
  164. #
  165. # Running the server
  166. #
  167. show -c "Start server $server"
  168. run java -Djava.rmi.server.codebase="$codebase_url" $server &
  169.  
  170. # sleep to give the server time to start up and print its message
  171. run -v sleep 6
  172.  
  173. #
  174. # Run the appletviewer, after setting the class path back to the original
  175. # so that class loading is done via the codebase, not the class path.
  176. #
  177. show -v CLASSPATH=$origCLASSPATH
  178. CLASSPATH=$origCLASSPATH
  179.  
  180. show -c "Starting the appletviewer"
  181. run appletviewer index.html
  182.