标签:des style blog color io java ar 文件 2014
1.首先写了一个简单的java程序,一个死循环,不停地输出一句话。
2.把工程共享到svn上。
3.编写publish_test.sh脚本,实现svn源码的检出,调用ant编译、打包,以及其他准备操作。
<span style="font-size:18px;">. /home/testjava/publish/config.sh mkdir -p ${PUBLISH_TEST_SVN_ROOT} if [ `ls -la ${PUBLISH_TEST_SVN_ROOT} | wc -l` == 3 ] then svn checkout ${URL_SVN_TEST_ROOT} ${PUBLISH_TEST_SVN_ROOT} else svn update ${PUBLISH_TEST_SVN_ROOT} fi ant -buildfile ${PUBLISH_TEST_ROOT}/build.xml clean ant -f ${PUBLISH_TEST_ROOT}/build.xml mkdir -p ${PUBLISH_TEST_LOGS_ROOT} touch ${PUBLISH_TEST_LOG}</span>其中config.sh中是预先声明好的一些路径信息。
4.利用ant将工程编译、打包。这里要编写配置文件。我用的默认名字build.xml。
<span style="font-size:18px;"><?xml version="1.0" encoding="UTF-8" standalone="no"?> <project basedir="." default="build" name="test"> <property environment="env"/> <property name="root.path" value="/home/testjava/publish"/> <property name="db.path" value="${root.path}/testjava"/> <property name="db.svn.path" value="${db.path}/svn"/> <property name="db.source.path" value="${db.svn.path}/src"/> <property name="db.lib.path" value="${db.svn.path}/libs"/> <property name="db.output.path" value="${db.path}/output"/> <property name="db.binout.path" value="${db.output.path}/bin"/> <property name="db.jarout.path" value="${db.output.path}/jar"/> <property name="db.jar.name" value="testjava.jar"/> <property name="debuglevel" value="source,lines,vars"/> <property name="target" value="1.6"/> <property name="source" value="1.6"/> <path id="db.classpath"> <fileset file="${db.lib.path}/*.jar"> </fileset> </path> <target depends="build-db,pack-db" name="build"/> <target name="init"> <mkdir dir="${db.binout.path}"/> <mkdir dir="${db.jarout.path}"/> </target> <target name="clean"> <delete dir="${db.binout.path}"/> <delete file="${db.jarout.path}/${db.jar.name}"/> </target> <target depends="init" name="build-db"> <javac debug="true" debuglevel="${debuglevel}" destdir="${db.binout.path}" source="${source}" target="${target}" includeantruntime="on" encoding="utf8"> <src path="${db.source.path}"/> <classpath refid="db.classpath"/> </javac> </target> <target name="pack-db"> <jar destfile="${db.jarout.path}/${db.jar.name}" basedir="${db.binout.path}"/> </target> </project></span>
5.编写以服务器形式运行jar包工程的脚本。start.sh
<span style="font-size:18px;">java -Dserver_name=/home/testjava/publish/testjava/output -Djava.net.preferIPv4stack=true -server -Xmx1g -Xmn512m -cp /home/testjava/publish/testjava/output/jar/* test.system.Main</span>
首先在/etc/init.d 下写服务脚本testjava.sh。
<span style="font-size:18px;">#!/bin/sh #chkconfig: 35 20 80 #description: testjava server EXEC_PATH=/home/testjava/publish/testjava/output EXEC=start.sh pid="" if [ -x $EXEC+path/%EXEC ]; then echo "project not found..." exit 1 fi getpid() { pid=`ps axjf | grep "Dserver_name=${EXEC_path}" | grep -v "grep" | awk '{print $2}'` } stop() { getpid if [ -z ${pid} ] then echo "ERROR : server has not been started..." else echo "server is stoping..." kill -15 ${pid} fi } start() { getpid if [ -z ${pid} ] then echo "server is starting..." cd ${EXEC_PATH} ./${EXEC} >>logs/log 2>&1 & else echo "ERROR : server has been started already..." fi } restart() { stop start } case "$1" in start) start ;; stop) stop ;; restart) restart ;; status) status ;; *) echo "Usage: service $EXEC {start|stop|restart|status}" exit 1 esac exit 0</span>
最后 chkconfig --add autoruntest 添加服务。
7.编写最终的启动、停止脚本。
startall.sh
service testjava.sh startstopall.sh
service testjava.sh stop
==================================================================== -- end
标签:des style blog color io java ar 文件 2014
原文地址:http://blog.csdn.net/endlu/article/details/39394815