抛弃ant maven用bash来build 项目

xiaoxiao2024-08-23  493

受够了ant和maven

决定自己写脚本 一边写一边改吧  这个已经可以 编译 和拷贝资源文件了

build了一个29个包  123个java文件 用了3秒

下一步就是打包 发布 上传 版本库等等

#!/bin/bash ## java project builder tools ## create date 2009-04-02 ## version 0.0.1 ### define the source dir java_file_sources_dir=src out_put_dir=bin lib_directory=lib ###define the JAVA_HOME and PATH CLASSPATH if you needed #JAVA_HOME=/usr/lib/java/jdk1.6.0_11 #PATH=$JAVA_HOME/bin:$PATH export LANG=zh_CN.UTF-8 CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:"$out_put_dir/":"$java_file_sources_dir" for jar in `ls $lib_directory/*.jar` do CLASSPATH="$CLASSPATH:""$jar" done echo -e '\E[31;48m'"\033[1m **************************** build xmhi backgroud project start **************************** \033[0m" echo -e '\E[32;48m'"\033[1m JAVA_HOME : \033[0m" $JAVA_HOME echo -e '\E[32;48m'"\E[1m CLASSPATH : \E[0m" $CLASSPATH echo -e '\E[32;48m'"\E[1m PATH : \E[0m" $PATH clear_bin() { echo -e '\E[33;48m'"\033[1m start to clear project ...... \033[0m" if [ -e $out_put_dir ] ; then rm -rf "$out_put_dir" mkdir "$out_put_dir" else mkdir "$out_put_dir" fi } ## compile all the java source in the source dirctory to the output directory you defined compile_source() { # init a array for the all java source folder declare -a java_source_folder_array folder_number=0 for java_source_name in ` find $java_file_sources_dir/ -type f -name '*.java' ` do java_sources_names=${java_source_name%/*.java} has_it_flag=0 for i in ${#java_source_folder_array[@]} do if [ "${java_source_folder_array[$i]}" = "$java_sources_names" ] ; then has_it_flag=1 elif [ "$java_sources_names" = "$java_file_sources_dir/" ] ; then has_it_flag=1 fi done if [ "$has_it_flag" = 0 ] ; then let "folder_number+=1" java_source_folder_array[$folder_number]="$java_sources_names" fi #javac -encoding "UTF-8" -d $out_put_dir "$java_sources_names" done echo -e '\E[33;48m'"\033[1m start to compile java source ...... \033[0m" #echo "total source folder number :" "${#java_source_folder_array[@]}" #echo "total source folders :" "${java_source_folder_array[@]}" echo "total package number : " "$[folder_number]" java_source_files="" for (( a=1 ; a <= $[folder_number] ; a++ )) do java_source_files="$java_source_files ""${java_source_folder_array[$a]}""/*.java" #javac -encoding "UTF-8" -nowarn -d $out_put_dir $java_source_files done echo "java source files name : " "$java_source_files" echo "total java source count :" ` find $java_file_sources_dir/ -name *.java |wc -l ` javac -encoding "UTF-8" -nowarn -d $out_put_dir $java_source_files echo "total class file count :" ` find $out_put_dir/ -name *.class |wc -l ` } ## copy the resource not include java source copy_resources_files() { echo -e '\E[33;48m'"\033[1m start to copy resource file ...... \033[0m" for resources_file_name in `find $java_file_sources_dir/ \( -type f -name '**.java*' -o -type d -o -path '*.svn*' \) -o -print` do #get the file name not include the resource path name resource_file_name_nsp=${resources_file_name#"$java_file_sources_dir/"} echo $resource_file_name_nsp #copy the resource file to the output directory cp -fu $resources_file_name "$out_put_dir""/$resource_file_name_nsp" done } start() { if [ -z $1 ] ; then clear_bin compile_source copy_resources_files fi } time start echo -e '\E[31;48m'"\033[1m **************************** build xmhi backgroud project end **************************** \033[0m"
转载请注明原文地址: https://www.6miu.com/read-5017819.html

最新回复(0)