jar-wrapper.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2007 The Android Open Source Project
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. # Set up prog to be the path of this script, including following symlinks,
  17. # and set up progdir to be the fully-qualified pathname of its directory.
  18. prog="$0"
  19. while [ -h "${prog}" ]; do
  20. fullprog=`/bin/ls -ld "${prog}"`
  21. fullprog=`expr "${fullprog}" : ".* -> \(.*\)$"`
  22. if expr "x${fullprog}" : 'x/' >/dev/null; then
  23. prog="${fullprog}"
  24. else
  25. progdir=`dirname "${prog}"`
  26. prog="${progdir}/${fullprog}"
  27. fi
  28. done
  29. oldwd=`pwd`
  30. progdir=`dirname "${prog}"`
  31. cd "${progdir}"
  32. progdir=`pwd`
  33. prog="${progdir}"/`basename "${prog}"`
  34. cd "${oldwd}"
  35. jarfile=`basename "${prog}"`.jar
  36. jardir="${progdir}"
  37. if [ ! -r "${jardir}/${jarfile}" ]; then
  38. jardir=`dirname "${progdir}"`/framework
  39. fi
  40. if [ ! -r "${jardir}/${jarfile}" ]; then
  41. echo `basename "${prog}"`": can't find ${jarfile}"
  42. exit 1
  43. fi
  44. declare -a javaOpts=()
  45. while expr "x$1" : 'x-J' >/dev/null; do
  46. opt=`expr "$1" : '-J-\{0,1\}\(.*\)'`
  47. javaOpts+=("-${opt}")
  48. shift
  49. done
  50. exec java "${javaOpts[@]}" -jar ${jardir}/${jarfile} "$@"