LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 620|回复: 1

写了个build java工程的

[复制链接]
发表于 2009-4-2 19:44:32 | 显示全部楼层 |阅读模式
实在是受够了ant 和 maven
于是自己写了一个
  1. #!/bin/bash
  2. ## java project builder tools
  3. ## create date 2009-04-02
  4. ## version 0.0.1
  5. ### define the source dir
  6. java_file_sources_dir=src
  7. out_put_dir=bin
  8. lib_directory=lib
  9. ###define the JAVA_HOME and PATH CLASSPATH if you needed
  10. #JAVA_HOME=/usr/lib/java/jdk1.6.0_11
  11. #PATH=$JAVA_HOME/bin:$PATH
  12. export LANG=zh_CN.UTF-8
  13. CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:"$out_put_dir/":"$java_file_sources_dir"
  14. for jar in `ls $lib_directory/*.jar`
  15.     do
  16.         CLASSPATH="$CLASSPATH:""$jar"
  17.     done
  18. echo -e '\E[31;48m'"\033[1m ****************************        build xmhi backgroud project start        **************************** \033[0m"
  19. echo -e '\E[32;48m'"\033[1m JAVA_HOME : \033[0m" $JAVA_HOME
  20. echo -e '\E[32;48m'"\E[1m CLASSPATH : \E[0m" $CLASSPATH
  21. echo -e '\E[32;48m'"\E[1m PATH : \E[0m" $PATH
  22. clear_bin()
  23. {
  24.     echo -e '\E[33;48m'"\033[1m start to clear project ...... \033[0m"
  25.     if [ -e $out_put_dir ] ; then
  26.         rm -rf "$out_put_dir"
  27.         mkdir "$out_put_dir"
  28.     else
  29.         mkdir "$out_put_dir"
  30.     fi       
  31. }
  32. ## compile all the java source in the source dirctory to the output directory you defined
  33. compile_source()
  34. {   
  35.     # init a array for the all java source folder
  36.     declare -a java_source_folder_array
  37.     folder_number=0
  38.     for java_source_name in ` find $java_file_sources_dir/ -type f -name  '*.java' `
  39.         do
  40.             java_sources_names=${java_source_name%/*.java}
  41.             has_it_flag=0
  42.             for i in ${#java_source_folder_array[@]}
  43.                 do
  44.                    if [ "${java_source_folder_array[$i]}" = "$java_sources_names" ] ; then
  45.                        has_it_flag=1
  46.                    elif [ "$java_sources_names" = "$java_file_sources_dir/" ] ; then
  47.                        has_it_flag=1
  48.                    fi
  49.                 done
  50.             if [ "$has_it_flag" = 0 ] ; then
  51.                 let "folder_number+=1"
  52.                 java_source_folder_array[$folder_number]="$java_sources_names"        
  53.             fi
  54.             #javac -encoding "UTF-8" -d $out_put_dir "$java_sources_names"
  55.         done
  56.     echo -e '\E[33;48m'"\033[1m start to compile java source ...... \033[0m"
  57.     #echo "total source folder number  :"  "${#java_source_folder_array[@]}"
  58.     #echo "total source folders :"  "${java_source_folder_array[@]}"
  59.     echo "total package number : " "$[folder_number]"
  60.     java_source_files=""
  61.     for (( a=1 ; a <= $[folder_number] ; a++ ))
  62.         do
  63.              java_source_files="$java_source_files ""${java_source_folder_array[$a]}""/*.java"
  64.              #javac -encoding "UTF-8" -nowarn -d $out_put_dir  $java_source_files
  65.         done
  66.     echo "java source files name : "  "$java_source_files"
  67.     echo "total java source count :" ` find $java_file_sources_dir/ -name *.java |wc -l `
  68.     javac -encoding "UTF-8" -nowarn -d $out_put_dir  $java_source_files
  69.     echo "total class file  count :" ` find $out_put_dir/ -name *.class |wc -l `
  70. }
  71. ## copy the resource not include java source
  72. copy_resources_files()
  73. {   echo -e '\E[33;48m'"\033[1m start to copy resource file ...... \033[0m"
  74.     for resources_file_name in `find $java_file_sources_dir/  \( -type f  -name '**.java*' -o -type d -o -path  '*.svn*' \)  -o -print`
  75.         do
  76.             #get the file name not include the resource path name
  77.             resource_file_name_nsp=${resources_file_name#"$java_file_sources_dir/"}
  78.             echo $resource_file_name_nsp
  79.             #copy the resource file to the output directory
  80.             cp -fu $resources_file_name "$out_put_dir""/$resource_file_name_nsp"
  81.         done
  82. }
  83. start()
  84. {
  85.     if [ -z $1  ] ; then
  86.         clear_bin
  87.         compile_source
  88.         copy_resources_files
  89.     fi
  90.             
  91. }
  92. time start
  93. echo -e '\E[31;48m'"\033[1m ****************************        build xmhi backgroud project end        **************************** \033[0m"
复制代码
发表于 2009-4-2 21:05:46 | 显示全部楼层
多了还是用ant方便,maven太依赖网络了。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表