Hibernate _ note 7 (Ant)

Source: Internet
Author: User

If you are not using IDE to run or test a project in Hibernate, you must first compile the application and start the database management system using the correct database Schema.
Ant is a powerful Java build system. Compile a build. xml file for the project and use the Ant command line tool to call the build task defined in the file. If supported, you can also call Ant tasks from Java IDE.
I have never touched the Ant concept before, so I checked some related resources on the Internet, as shown below.
What is Ant? Apache Ant is a Java-based generation tool.
In software development, generation tools are used to convert source code and other input files into executable files (or install product images ). As the application generation process becomes more complex, make sure that the same generation steps are exactly the same during each generation, and implement as much automation as possible to generate consistent versions in a timely manner.
1. Install Ant at http://ant.apache.org/bindownload.cgito download the Ant package.
Decompress the entire package
For example, I placed it in E: \ soft \ apacheAnt.
Set ANT_HOME = E: \ soft \ apacheAnt in Environment Variables
Add: % ANT_HOME % \ bin to the ClassPath and Path of the environment variable.
Enter ant in the command line
Build. xml does not exist!
Build failed
Installed successfully
2. Compile an ant Build File
public class HelloWorld {public static void main(String[] args) {System.out.println("Hello World");}}
Run the first build
Open the command window, go to the directory where the java program is stored, and type: ant in the command line.
Scenario 1: for example, in my first Ant project
Run cmd
D: d Disk
Cd firstAnt to the specified directory
Ant runs java program
Case 2:
I am a Windows 7 7 system. shift + Right-click the firstAnt project and choose> open the command window here.
Although ant can be used to compile files, the construction process is very messy. All kinds of files are in the same folder (such as source files and target files). If the project is bigger, it will be very messy, difficult to control. Therefore, we need to enforce control to completely separate the source file from the generated file and put it under different directories.
The Ant project separates source files, intermediate files, and release packages in different directories for ease of management and integration of similar files:
Directory
Src Source File
Build/classes intermediate file (generated, can be cleaned)
Dist files that can be published (generated and cleaned)

Directory Function
Src Source File
Bin Intermediate file (generated, cleanup)
Lib Jar package

Project Task: each build file corresponds to a project. Build the root tag of the file when the tag is used. It can have multiple internal attributes, as shown in the Code. The meanings of each attribute are as follows.
(1) default indicates the default running target. This attribute is required.
(2) basedir indicates the baseline directory of the project.
(3) name indicates the project name.
(4) description indicates the description of the project.
Target Task: A project tag can contain one or more target tags. A target tag can depend on other target tags.
For example, one target is used to compile the program, and the other target is used to generate executable files. You must compile this file before generating an executable file. Therefore, the target of the executable file depends on the target of the compiled program. All properties of Target are as follows.
(1). name indicates that this attribute is required.
(2). depends indicates the target of the dependency.
(3) if indicates that it is executed only when the attribute is set.
(4) unless: it is executed only when the property is not set.
(5) description indicates the description of the project.
Property Task: a project can have many properties. Property tasks can be set in buildfile or outside Ant. A property has a name and a value. Property can be used as the attribute value of a task. This is achieved by placing the attribute name between "{" and "}" and the attribute value. For example, if the value of a property builddir is "build", this property can be used for the property value {builddir}/classes. This value can be parsed to build/classes.
Path Task: the Path element is used to represent a class path, but it can also be used to represent other paths. When used as several attributes, the items in the path are separated by semicolons or colons. During construction, this separator replaces all path delimiters on the current platform. Its Attributes are as follows.
(1). location indicates a file or directory. Ant expands this field to an absolute path.
(2). refid is a reference to a path defined somewhere in the current build file.
(3). path indicates a list of files or path names.
Filterset Task: Filterset defines a set of filters that replace the file text when the file is moved or copied.
The main attributes are as follows:
(1). begintoken indicates the mark searched by the nested filter, which is the string that marks its start.
(2). endtoken indicates the mark searched by the nested filter. This is the string that marks its end.
(3). id is the unique identifier of the filter.
(4). refid is a reference to defining a filter somewhere in the build file.
Patternset Task: Fileset is a group of files, while patternset is a group of patterns. They are closely related concepts. Four attributes are supported: includes excludex includexfile and excludesfile, which are the same as fileset. Patternset also allows the following nested elements: include, exclude, includefile, and excludesfile.
Mkdir Task:
This label is used to create a directory. It has a dir attribute to specify the name of the Created directory.
Delete Task: This label is used to delete a file or a group of files. Its Attributes are as follows.
(1)/file indicates the file to be deleted.
(2). dir indicates the directory to be deleted.
Javac Task: This label is used to compile one or more java files. Its Attributes are as follows.
(1). srcdir indicates the directory of the source program.
(2). destdir indicates the output directory of the class file.
(3). include indicates the mode of the compiled file.
(4). excludes indicates the mode of excluded files.
(5). classpath indicates the class path used.
(6). debug indicates the debugging information contained.
(7). optimize indicates whether to use optimization.
(8). verbose indicates providing detailed output information.
(9). fileonerror indicates that it is automatically stopped when an error occurs.
(3). includeEmptyDirs indicates whether to delete an empty directory. The default value is Delete.
(4). failonerror indicates whether to stop an error. The default value is automatic stop.
(5). verbose indicates whether to list the deleted files. The default value is not listed.
Java Task: This label is used to execute the compiled. class file. Its Attributes are as follows.
(1). classname indicates the name of the class to be executed.
(2). jar indicates the JAR file name containing the class.
(3). classpath indicates the class path used.
(4). fork indicates that the class is run in a new virtual machine.
(5). failonerror indicates automatic stop when an error occurs.
(6). output indicates the output file.
(7). append indicates appending or overwriting the default file.

Ant Build. xml file

   
   
    
    
    
    
    
    
    
    
    
     
      
      
     
    
    
    
     
     
    
    
    
     
     
    
    
    
     
     
      
     
    
    
    
     
      
       
      
     
    
    
    
     
      
     
    
   

Summary:

Note 5: There is a Hibernate project created using the MyEclipse IDE tool and Ant

1. For example, create the firstAnt directory on disk D.

2. Copy src from the Hibernate project.

3. Copy the lib in the Hibernate Project

4. run ant run in cmd.

I just got started with Ant, but I still don't know much about it. I don't know what it means.

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.