自动编译脚本 build.sh, 放置在项目根目录下。
#!/bin/bash # check args # init path CURRPATH=`pwd` LIBDIR="$CURRPATH/WebContent/WEB-INF/lib" SRC="$CURRPATH/src" CLASS="$CURRPATH/WebContent/WEB-INF/classes" if [ -a $CLASS ]; then rm -rf $CLASS/* else mkdir $CLASS fi CLASSPATH="$CLASSPATH" TMP=`find $LIBDIR -name "*.jar" | awk '{var=$0":"var;}END{print var;}'` CLASSPATH="$TMP$CLASSPATH" echo "classes:$CLASS" javac -sourcepath $SRC -classpath $CLASSPATH -d $CLASS `find $SRC -name "*.java"` WebContent/deploy.sh
自动部署脚本 deploy.sh,放置在WebContent/目录下。
#!/bin/bash # check args PROJ="UFE" WAR="$PROJ.war" if [ $# -ne 1 ]; then TOMCAT="/usr/local/tomcat" else TOMCAT=$1 fi BAK="$TOMCAT/bak" if [ -a $BAK ]; then ls $BAK else mkdir $BAK fi if [ -a $WAR ]; then rm -f $WAR fi WEBROOT=`pwd` if [ -a $WAR ]; then rm -f $WAR fi echo "jar -cvf $WAR " jar -cfM $WAR . BAKWAR="$BAK/$WAR" if [ -a $BAKWAR ]; then i=1 while [[ -a $BAK/$WAR.$i ]] do ((i++)) done mv $BAKWAR $BAK/$WAR.$i fi $TOMCAT/bin/shutdown.sh DIS="$TOMCAT/webapps/$WAR" if [ -a $DIS ]; then mv $DIS $BAKWAR rm -f $DIS fi Folder="$TOMCAT/webapps/$PROJ" if [ -a $Folder ]; then rm -rf $Folder fi cp $WAR $DIS $TOMCAT/bin/startup.sh