Leverage Ant and eclipse to effectively improve deployment efficiency

Source: Internet
Author: User
Tags file system log4j

The reader is positioned as a developer with experience in Java and Ant usage.

Readers can learn how to use ANT to solve problems that are compiled into different deployment packages based on different target environments in several multiuser development environments.

Working scene

Now there is a Web project that is developed by many people and managed by CVS. In addition, the project also has some testers, they test the application deployed on the test server, notify the developer through the bug management system after the bug is found, and after the developer fixes the bug and is tested locally, the specialized person is responsible for the checkout (check out) code, compiled and packaged, and deployed to the test server.

A member of this project is the person who is responsible for checking out code, compiling and packaging, and deploying to the server. In addition to this task, he is also a programmer for the project. After the project has entered the testing phase, small A is after the message that the other members of the group have fixed the bug and checked in (check in) code (it is also possible that little a has checked in the code himself), little a first updates the local code, tests locally, confirms that the bug is fixed, and then deploys it to the test server. and notifies the tester that the bug has been fixed and that the tester continues with the test.

Little A's troubles

In this project, there are some code and pages written to facilitate the development of the test, for example, skip user authentication, but when deployed to the test machine environment, you need to delete the code and the page, and as a flexible and extensible application, there are some configuration files, the value in the configuration file will change depending on the environment. For example, the log4j logging is used in the project, and the log4j is required to specify the save path for the log file, which is developed by the local programmer with a Windows system and a Windows file system assigned to log4j, which needs to be deployed to the Linux system during the testing phase. Then the log's save path also needs to make the corresponding change. When deploying to a test server, there are a number of other configuration items that need to be changed, in addition to log4j, and scattered across the package. Little A's troubles follow, and every time he finishes his local test, according to the needs of the tester to find the configuration file, change the corresponding value, and delete those for the test to write code and pages, may do several times a day to do such things, the most annoying is that he quickly finished the test machine environment changes, A developer suddenly notice small a said: "I changed a little bit of code, just check in, you have to redo a bag." , small A has to start from scratch to do a new round of checkout code, local testing, change configuration files, delete unwanted files, packaged deployment work. In addition, small A was notified later in the test phase that it was necessary to generate a war package in the product environment in addition to the war package for each test environment, and he did more.

From the above scenario, it can be seen that small a is inefficient and error prone, and may even lead to inefficient work of the entire project. You can actually use ANT to help small A to do this work quickly and efficiently. In Ant, you can write the project set of all the configuration files you want to change into a configuration file, depending on the needs of your target environment. In this way, depending on the target environment to get different profiles, Ant in the compilation package according to different target environment switch different configuration files. For example, little a now encounters 3 of environments: the development environment, the test environment, and the product environment, which can generate three different profiles based on these three environments: Develop_deploy.property, Test_deploy. Property and Product_deploy. property, just switch between these three profiles when small a wants to generate a different package.

We need to download and install the appropriate software before we start writing the script formally.

Eclipse: To make Ant development simpler, we chose Eclipse3.1 as the development environment. Of course you can use any of your favorite text editing tools to develop your Ant. The latest version of Eclipse can be downloaded from the http://eclipse.org/.

Ant:ant is a Java-based compilation tool, like make in C + +, but not as hard as make. The latest version of ANT can be downloaded from the http://ant.apache.org/bindownload.cgi. If you use eclipse to develop ant, you don't have to download ant separately, because Ant is already integrated in eclipse.

CVS Client (cvs.exe): CVS can be downloaded from http://www.nongnu.org/cvs/

Using Eclipse3.1 to create an Ant script

If you use Eclipse to write Ant, it is recommended that you use Eclipse version 3.1. The Eclipse3.1 version adds a number of new features, in addition to the syntax highlighting previously provided by the ANT editor, hints of syntax errors, and so on. For example: The collapse of the script code, a quick positioning of the definition of a property or target segment, the refactoring of the property name and target name in the same builder file (shortcut ALT + Shift +r), debugging Ant scripts, and so on.

Now let's take a look at the support for Ant in Eclipse 3.1.

Open "File"-"New"-"project"-"Simple"-"project", click "Next", enter the project name "Ant", and then click until "Finish"

In the new Ant project, create a new Test.xml and copy the following script. The contents of the script are not introduced, and we mainly look at what Eclipse provides. Note that this is not the Ant editor, and after copying the contents, turn off the open "Test.xml" and reopen it, so that Eclipse will open it with the Ant editor and the syntax is highlighted.

<?xml version="1.0" encoding="UTF-8"?>
<project name="Test" default="init" basedir=".">
<property name="test" value="test"/>
<target name="init">
   <echo>${test}</echo>
</target>
</project>

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.