Write an automatically updated program for Java applications for multiple machines __java

Source: Internet
Author: User
Problem: The existing 70-seat PC step-by-Step installation of the Java application has already installed Java applications on 10 machines. If the code changes, only through Remote Desktop connection to the front of the computer for manual operation. Such a day is wasted in such a boring time.
Idea: The use of the FTP server has been built to achieve the automatic updating of the program, thus liberating their own labor, but also to ensure the timely updating of the process of the previous machine.
Ideas:
1, create a test directory d:/ftp in the local directory of the predecessor, new version/ Version.txt and startup.properties two files and folders, where version.txt as the primary file to determine whether the program needs to be upgraded, Startup.properties is the Java application directory to start when the update is complete. Configure the update to the D:/FTP directory.
2, on the FTP server fixed program Download directory ftp://XXX/update/ , the test directory is shown below:
3, running the local program D:/ftp/update/update.bat files, the directory structure to get the following figure:
4, the update program first from the front of the local file check to get version/version.txt files, if not the file, the first shutdown of the running Java program, and from the FTP update directory download all the information including version. If Version.txt is in memory read, download from FTP server/update/version/version.txt and overwrite to local version/ Version.txt the file and reads it into Java memory, compares the Versin objects in memory and does not update them if they are the same.
5, update complete, release the relevant resources, and start the shutdown of the Java application.
Idea diagram:
Difficult:
1, the program to run using a bat file to start running, in the process of all the Java running programs are Java.exe, how to distinguish the bat-initiated Java.exe process and to close.
2, FTP download upload and FTP specified directory all the resources of the traversal has not been written in Java before, how to achieve?
3, the program shut down again to run the command set to start bat, here good around people, spent a little time.
Solve:
The first problem is solved by using one of the methods. BAT file startup Java.exe, that copy the same name in the J2se\bin and rename it to its own designation, modify bat to call its own renamed Java.exe, so in the window process manager can see their own named Java.exe, Then use the runtime class to execute the cmd command: taskkill/f/im Java (renamed). EXE to close all startup processes.
The second question: in the network search for a predecessor to write the relevant code, the selection of code quality is relatively high as the source of their own learning FTP upload download and other related operations examples. Use the Apache Commons package's FtpClient API to implement FTP-related operations.
Third question: Use the EXEC (String  command) method of the runtime class to execute the cmd.exe/c start/min +directory+xx.bat command, report an exception, Unable to function properly, after several twists and starts, the default path for this method is to start the directory where the class bat file is located, so that the execution file cannot be found. Later, the executable file can be found by the adjustment directory, but the shutdown program cannot be started correctly, which is due to the incorrect traversal of the new CMD window. The query API finds exec (string[] cmdarray,string[] envp,File  dir) This method, described in the API, executes the specified command and variable in a separate process in the specified environment and working directory. This is what you want to use. After adjusting, you can finally start the closed bat file correctly. 
Summarize:
This function module wants to be simpler, the code implementation is also very simple, the function and the program may also have the bug.
The exception capture and log output codes are not updated.
Source code: http://download.csdn.net/source/3536310
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.