Java server shallow into the shallow out of the brief Java program release

Source: Internet
Author: User
Tags svn update

This article will document the deployment settings for a simple Java program on Linux, as well as the writing of the release script.  Rough, brief. Magic! Don't move

1. First write a simple Java program, a dead loop, constantly output a word.


2. Share the project to SVN.


3. Write the publish_test.sh script, implement the SVN source checkout, call ant compile, package, and other preparation operations.

<span style= "FONT-SIZE:18PX;" . /home/testjava/publish/config.shmkdir-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}fiant- BuildFile ${publish_test_root}/build.xml cleanant-f ${publish_test_root}/build.xmlmkdir-p ${PUBLISH_TEST_LOGS_ROOT }touch ${publish_test_log}</span>
Some of the path information in config.sh is pre-declared.


4. Use ant to compile and package the project. Here you write the configuration file. I use the default name 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.PA Th}/svn "/> <property name=" Db.source.path "value=" ${db.svn.path}/src "/> <property name=" db.lib.p Ath "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.ou Tput.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}"/&G        T </target> <target name= "clean" > <delete dir= "${db.binout.path}"/> & Lt;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} "t                arget= "${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&gt ;</project></span>

The clean here can be set to build dependencies, which I did not write. Javac compiles the source code into Class,jar to package the class into a jar package.


5. Write a script that runs the Jar package project as a server. 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>


6. Establish a system service Testjava with the goal of running start.sh.

First write the service script testjava.sh under/ETC/INIT.D.

<span style= "FONT-SIZE:18PX;" >#!/bin/sh#chkconfig:35 80#description:testjava serverexec_path=/home/testjava/publish/testjava/outputexec= Start.shpid= "" If [-X $EXEC +path/%exec]; Thenecho "Project not found ..." Exit 1figetpid () {pid= ' ps AXJF | grep "Dserver_name=${exec_path}" | Grep-v "grep" | awk ' {print $} '}stop () {getpidif [-Z ${pid}]then echo "Error:server have not been started ..." Else echo "        Server is stoping ... "kill-15 ${pid}fi}start () {getpidif [-Z ${pid}]then echo" Server is starting ... " CD ${exec_path}./${exec} >>logs/log 2>&1 &else echo "Error:server has been started Al        Ready ... "Fi}restart () {Stop start}case" $ "in start) start;        stop) stop;;        restart) restart;;  status) status; *) echo "Usage:service $EXEC {start|stop|restart|status}" exit 1esacexit 0</span>

Where log redirection is 2>&1 the error message is transferred to normal output to standard & is to run this statement in the background.

Finally Chkconfig--add autoruntest Add the service.


7. Write the final start and stop scripts.

startall.sh

Service testjava.sh Start
stopall.sh

Service testjava.sh Stop


at this point, a simple release process is complete. Whenever a version update needs to be published, if the server is running, the stopall.sh is executed first. Then perform the publish_test.sh release. The last execution startall.sh starts. The run-time log is viewed in the pre-redirected Logs/log file.

====================================================================--End

Java server shallow into the shallow out of the brief Java program release

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.