利用shell自动化打包java工程

Java代码 利用shell自动化打包java工程
文章图片

  1. #!/bin/bash
  2. #wuzhong@taobao.com
  3. #打包工程用
  4. usage()
  5. {
  6. echo 'build.sh -s(svn up) -x(antx.properties) -m(mvn clean package) -a(do all) kjava/wtm ]'
  7. exit 1
  8. }
  9. #usage
  10. NEED_MVN=1
  11. while getopts "sxma:" options; do
  12. case $options in
  13. s) echo "svn up"
  14. HAS_OPT=1
  15. NEED_SVN=1; ;
  16. x) echo "copy antx properties"
  17. HAS_OPT=1
  18. NEED_ANTX=1; ;
  19. m) echo "mvn clean package"
  20. HAS_OPT=1
  21. NEED_MVN=1; ;
  22. a) echo "do all: svn up , antx properties , mvn clean package"
  23. HAS_OPT=1
  24. NEED_MVN=1
  25. NEED_SVN=1
  26. NEED_ANTX=1; ;
  27. *) usage; ;
  28. esac
  29. done
  30. #APP_NAME=wtm
  31. APP_PATH=/home/wuzhong/workspace/
  32. #获取最后一个参数
  33. RELATIVE_PATH=${!#}
  34. APP_NAME=$(basename $RELATIVE_PATH)
  35. #对参数做判断
  36. #if [ $HA ]
  37. APP_PATH=${APP_PATH}${RELATIVE_PATH}
  38. echo "app path is : $APP_PATH ; app name is $APP_NAME "
  39. [ $NEED_ANTX ] && if [ -f /home/wuzhong/work/${APP_NAME}_antx.properties ]
  40. then
  41. echo "copy antx properties from " /home/wuzhong/work/${APP_NAME}_antx.properties
  42. cp /home/wuzhong/work/${APP_NAME}_antx.properties /home/wuzhong/antx.properties
  43. else
  44. echo "===============antx.properties is not exist=============="
  45. exit 0
  46. fi
  47. if [ ! -d $APP_PATH ]
  48. then
  49. echo "==============project doesnot exit==========" ;
  50. exit 0
  51. fi
  52. if [ $NEED_SVN ]
  53. then
  54. cd $APP_PATH
  55. svn up
  56. fi
  57. if [ $NEED_MVN ]
  58. then
  59. cd $APP_PATH
  60. mvn clean package
  61. fi

    推荐阅读