自己常用的一個java應用程式模板,節省了不少時間!
包含很多指令碼:
 
一、啟動指令碼
 
starup.bat
set APP_LIBDIR=..\lib 
setlocal EnableDelayedExpansion 
set APP_CLASS_PATH=%XFIRE_HOME% 
for %%c in ("%APP_LIBDIR%\*.jar"do set APP_CLASS_PATH=!APP_CLASS_PATH!;%%c 
set APP_CLASS_PATH 
java -cp %APP_CLASS_PATH% com.lavasoft.TestMain
 
startup.sh
#!/bin/sh 

programdir="." 
program="com.lavasoft.TestMain" 

num=$# 
temp=$CLASSPATH 
#setting libs path 
libs=../lib/* 
append(){ 
                temp=$temp":"$1 

for file in $libs;    do 
                append $file 
done 
export CLASSPATH=$temp:.:../:$programdir 
export LANG=zh_CN 
res=`ps aux|grep java|grep $program|grep -v grep|awk '{print $2}'` 
if [ -n "$res" ] 
     then 
                echo "TestMain already running" 
else 
             java -classpath $CLASSPATH    com.lavasoft.TestMain & 
             sleep 3 
                unset res 
                res=`ps aux|grep java|grep $program|grep -v grep|awk '{print $2}'` 
                if [ -n "$res" ] 
                    then 
                         echo "TestMain start success" 
                    else 
                         echo "TestMain start error" 
                 fi 
fi
 
二、log4j.properties
 
log4j.rootLogger=INFO,CONSOLE,LOGFILE 

## CONSOLE 
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender 
log4j.appender.Threshold=INFO 
log4j.appender.CONSOLE.Target=System.out 
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout 
log4j.appender.CONSOLE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss } - %-5p %c        %x - %m%n 

## logfile 
log4j.appender.LOGFILE=org.apache.log4j.RollingFileAppender 

log4j.appender.LOGFILE.File=testapp.log 
log4j.appender.LOGFILE.MaxFileSize=10MB 
log4j.appender.LOGFILE.MaxBackupIndex=10 
log4j.appender.LOGFILE.layout=org.apache.log4j.PatternLayout 
log4j.appender.LOGFILE.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss } -    %-p %c     %x - %m%n
 
三、build.xml
 
<?xml version="1.0" encoding="UTF-8"?> 
<project name="testapp" basedir="." default="compile"> 

        <property environment="env"/> 
        <property name="build.dir" value="./testapp"/> 
        <property name="classes.dir" value="${build.dir}/bin"/> 
        <property name="dist.dir" value="./testapp"/> 

        <path id="classpath"> 
                <fileset dir="./lib"> 
                        <include name="*.jar"/> 
                </fileset> 
        </path> 

        <target name="compile" depends="clean"> 
                <mkdir dir="${build.dir}"/> 
                <mkdir dir="${classes.dir}"/> 
                <mkdir dir="${build.dir}/lib"/> 
                <copy toDir="${classes.dir}" failonerror="false"> 
                        <fileset dir="./src"> 
                                <include name="**/*.*"/> 
                                <exclude name="**/*.java"/> 
                                <exclude name="**/*.log"/> 
                                <exclude name="**/*.iws"/> 
                                <exclude name="**/*.ipr"/> 
                                <exclude name="**/*.iml"/> 
                        </fileset> 
                </copy> 
                <copy toDir="${build.dir}/lib" failonerror="false"> 
                        <fileset dir="./lib"> 
                        </fileset> 
                </copy> 
                <javac debug="on" 
                             fork="true" 
                             encoding="GBK" 
                             destdir="${classes.dir}" 
                             srcdir="./src" 
                             extdirs="**/test/**" 
                             classpathref="classpath"> 
                </javac> 
        </target> 

        <target name="jar" depends="compile"> 
                <mkdir dir="${dist.dir}"/> 
                <copy toDir="${dist.dir}" failonerror="false"> 
                        <fileset dir="./src"> 
                                <include name="*.xml"/> 
                                <include name="*.properties"/> 
                                <include name="*.sh"/> 
                        </fileset> 
                </copy> 
                <jar destfile="${dist.dir}/testapp.jar"> 
                        <fileset excludes="**/Test*.class,**/*.xml,**/*.properties,**/*.log,**/*.sh" dir="${classes.dir}"/> 
                </jar> 
        </target> 

        <target name="clean"> 
                <delete dir="${build.dir}"/> 
                <delete dir="${dist.dir}"/> 
                <delete dir="${build.dir}/lib"/> 
        </target> 
        <target name="all" depends="clean,compile,jar"/> 
</project>