Ant provides a rich Task, which is developed by the Apache Ant project group, and has been tested by all users, and features are very stable and have cross-platform features. So when a programmer develops certain functions, if these features are included in the Task, you can directly reference this feature, and the mechanism of Ant can easily apply the Task's Task to the Java program.
The following is an example, this example, the F: / Study / Test1 directory is f: /study/mytest.jar package. Package mytest;
Import org.apache.tools.ant. *; import org.apache.tools.ant.taskdefs. *; import org.apache.tools.ant.types. *; import java.io.file;
Public class testjar {public testjar () {} public static void main (string [] args) {Testwar testwar1 = new testwar (); testwar1.jar ();
Public static void jar () {PUBLIC JARER EXTENDS JAR {public jarr () {project = new project (); project.init (); tasktype = "jar"; TASKNAME = "jar"; target = new target (); }
Jarr Jar = new jarr (); jar.setdestfile (new file ("f: //study/Mytest.jar")); jar.setBasedir (New file ("f: // study // test1));
jar.execute ();
}
} In this example, the JAR class in the Ant task is applied. From this class inherits a new class JARER, the functionality of the Jarr class is to create the Project and Target objects. During future use, you can create a JARER class object, and then set the JARER's parameters, and finally call JARER's Execute () method.
Note: Compile, run, run, only you need to add Ant's ANT.jar package to the ClassPath path.