Implementation of automatic upgrade of Java CS structure software

Source: Internet
Author: User

Some time ago did a tool released to the company's various departments after the use of feedback a lot of bugs, each modification will need to send an email to notify each user to replace the latest version, very inconvenient, so later wrote an automatic upgrade function, so that each release of the new version only need to deploy it to the automatic upgrade server, Tools connect to the automatic upgrade server when they run the tool, check for version updates, and run the current version of the tool if there is an update and then run the latest build.

To make this auto-upgrade module Versatile, I made it possible to run a standalone program instead of integrating it into a tool, which provides the ability to automatically upgrade a variety of software. The automatic upgrade module uses the socket method to upgrade the client-server interaction. Version control file Autoupdate.xml to control the version of the update, the completion of the automatic Update will be the history of the list history.htm also sent to the client, and automatically open the file, so that the user can be the specific content of the upgrade at a glance.

Detailed implementation:
Autoupdate.xml Specific content:

1<?xml version= "1.0" encoding= "GBK"?>
2<info>
3 <Version>1.0.3</Version>
4 <UpdateServer>
5 <Ip>122.2.14.212</Ip>
6 <Port>2110</Port>
7 </UpdateServer>
8 <Files>
9 <File>
Ten <Name>mftest.jar</Name>
<Path>.\bin</Path>
<SubVer>1.0.0.3</SubVer>
</File>
<File>
<Name>run.bat</Name>
<Path>.</Path>
<SubVer>1.0.0.3</SubVer>
</File>
<File>
<Name>eglreco.fix</Name>
<Path>.\config\resource</Path>
<SubVer>1.0.0.0</SubVer>
</File>
<File>
<Name>eglrec.fix</Name>
<Path>.\config\resource</Path>
<SubVer>1.0.0.0</SubVer>
</File>
<File>
<Name>dom4j-1.6.1.jar</Name>
<Path>.\lib</Path>
<SubVer>1.0.0.0</SubVer>
</File>
<File>
<Name>jaxen-1.1-beta-4.jar</Name>
<Path>.\lib</Path>
Panax Notoginseng <SubVer>1.0.0.0</SubVer>
</File>
<File>
<Name>jxl.jar</Name>
<Path>.\lib</Path>
<SubVer>1.0.0.0</SubVer>
</File>
</Files>
45</info>

??? Where Updateserver user describes the IP and port of the server, version is the large version of the software, files for the software involved in the file, where the Subver is the version number of the specific file, others as the name implies.

History.htm Specific content:

1<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" >
234<title>xxx Software update History </title>
5<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
6<style type= "Text/css" >
7 body,table{
8 font-size:12px;
9 COLOR: #666666;
Ten font-family: Song body;
One background-color: #ffffff;
line-height:160%;}
</style>
1415
16<body>
17<table width= "border=" 1 "align=" center "cellpadding=" 2 "cellspacing=" 0 ">
<tr bgcolor= "#ECECEC" >
&LT;TD align= "center" width=50> version </td>
&LT;TD align= "center" width=470> Update content </td>
&LT;TD align= "center" width=80> Date </td>
</tr>
<tr>
&LT;TD align= "center" >1.0.3</td>
&LT;TD ><p>1. Implement auto-upgrade function <br>
26 2. Add version number display <br>
27 3. Fix ....<br>
</p>
</td>
&LT;TD align= "center" >2008-12-25</td>
</tr>
<tr>
&LT;TD align= "center" >1.0.2</td>
&LT;TD ><p>1. Fixed ... Errors that cannot be generated correctly with equal characters <br>
35 2. Fixed ... Unable to generate error <br>
</p>
Panax Notoginseng </td>
&LT;TD align= "center" >2008-12-20</td>
</tr>
40<tr>
&LT;TD align= "center" >1.0.1</td>
&LT;TD ><p>1. Increased by ...<br>
43 2. Correction because ... The error <br>
</p>
</td>
&LT;TD align= "center" >2008-12-15</td>
</tr>
48<tr>
&LT;TD align= "center" >1.0.0</td>
&LT;TD ><p>1. To achieve through .... function <br>
51 2. Achieve adoption .... function <br>
</p>
</td>
&LT;TD align= "center" >2008-12-11</td>
</tr>
56</table>
57</body>
58


Working principle:
The auto-upgrade client first sends the local autoupdate.xml content to the server, the server receives the client's version information and compares it to the server-side local version information (Autoupdate.xml), first comparing version, and if it is consistent, notifies the client that there is no need to update, and if the inconsistency checks fil Es in the subver of the files, the server will subver inconsistent files to the client, for the server has and the client does not have to send files to the client, after processing all file, The server sends the local history.htm to the client and notifies the client that the update is complete, and the client automatically opens the history.htm after receiving the update and displays the update history information to the user.

This implementation is based on the socket implementation, of course, the communication protocol is custom, but also a friend said that the use of HTTP protocol is relatively simple, of course, this is a method, but to use the HTTP protocol, the service side to have HTTP service will lead to the server is too large.


This implementation includes:
1. Aupd.java communication protocol between server and client

2, Autoupdateserver.java service side of the monitoring process
3, Aupdsrvproc.java service thread, for processing the client's automatic upgrade request
4. Clientverparser.java service-side service thread class for resolving client version information
5. Autoupdateclient.java Client Auto-upgrade request process
6, Config.java for the server and client to read the local configuration file class
7, Updfile.java file for file transfer to the image
This implementation uses DOM4J as the engine for interpreting XML

First, Aupd.java

/** *//********************************************************************   * Project name                : Rochoc

* Package Name: com.rochoc.autoupdate

* File name: Autoupdprotocol.java

* Written by: Kfzx-luoc

* Date of writing: 2008-12-22

* Program function (Class) Description:

* Define automatic Upgrade client and Server communication protocol * Program Change Date: * Change Author: * Change note: ********************************************************************/p Ackage com.rochoc.autoupdate; /** *//** * @author Kfzx-luoc * * TODO to change the template for this generated type comment go to * window-preferences -Java-code Style-code Templates */public class AUPD {/** *//** * meaningless operation */public static final String none = "None "; /** *//** * Send client version information */public static final String send_client_version = "Sendcver"; /** *//** * Receive client version information */public static final String received_client_version = "Recdcver"; /** *//** * Send file full path */public static final String Send_file_absoult = "SENDFILE"; /** *//** * Receive file Full path */public static final String Received_file_absoult = "Recdfile"; /** *//** * Start File transfer * * public static final String start_transmit = "STARTTSM"; /** *//** * End File Transfer */public static final String terminate_transmit = "TERMTSMT"; /** *//** * Update failed */public static final String updated_failure = "Updefail"; /** *//** * Update Successful */public static final String updated_successful = "UPDESUCC"; /** *//** * No need to update */public static final String notneed_updated = "NNEEDUPD"; /** *//** * is ready to receive the update file */public static final String ready_to_update = "Readytup"; /** *//** * Close link */public static final String BYE = "Byebyeok"; /** *//** * Data area OFFSET */public static final int data_offset = 5; /** *//** * File data block size */public static final int data_size = 1024; /** *//** * Send buffer size */public static final int buffer_size = data_size + 1 + 4; [0] bits are flag bits, differentiate data and COMMAND + 4 bit length/** *//** * Data Segment ID */public static final int mark_data_sect = 0; /** *//** * Command Segment identifier */public static final int cmd_data_sect = 1; /** *//** * Data segment End identifier */public static final int mark_data_end = 127; } Other source code (please download)
To run the service side:
Java-cp.;. \ bin;. \lib\dom4j-1.6.1.jar;. \lib\jaxen-1.1-beta-4.jar Com.icbc.autoupdate.AutoUpdateServer
To run the client:
Java-cp./bin;. /lib/jaxen-1.1-beta-4.jar;. /lib/dom4j-1.6.1.jar; Com.icbc.autoupdate.AutoUpdateClient

Implementation of automatic upgrade of Java CS structure software

Related Article

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.