Using Ant in JBuilder8

xiaoxiao2021-03-06  70

Use of ANT in JBuilder8: Weng Chi original in JBuilder8, Apache Ant version 1.5.1 has been updated to provide greater functionality. What is ANT? In general, Ant is a Java-based build tool. About Build Tools, I believe that everyone has already been exposed to many, such as: make, gnumake, nmake, jam, and other build tools. So why do you want to use Ant? Because Ant is a Java-based cross-platform build tool. ANT expands with Java classes, (users) Do not have to write shell commands, the profile is based on XML, perform tasks by the Targets and Tasks defined in the configuration file. JBuilder automatically identifies the build file of Ant's ANT named Build.xml, and this file in JBuilder will display an icon of an ant. The JBuilder version used herein is JBuilder8, which is assumed to have a certain understanding of JBuilder and Java. Let's take a step by step how to use Ant in JBuilder. 1. Establish an engineering and application to open JBuilder8, select Menu File | New to open the new panel. Select Project in Project, fill in the ANTPROject in the Name column, skip the steps below, press Finish to complete. Select File | New In the General panel, select Application, and accept the default option to finish the end. 2. Establish an ANT file in JBuilder Select Project | Add Files / Packages, select the explorer on the left, select the root directory of the ANTProject project, fill in the build.xml in the File Name field, press OK to play a prompt to ask if you want to create, press OK Just create a file called Build.xml. The system can automatically identify it is an Ant file and display it into an ant icon. If you have other names. XML files I hope JBuilder will identify it as an Ant's build file, right-click on this file, select Properties in the ANT page Select Ant Build File.

Open the build.xml file you just created, please save the project after adding the following contents Here: First look at the project of the third line, each build file contains a project, name is the project name, Default refers to a default target, a project can be defined One or more Targets. When performing Ant, you can choose to execute that Target. When no Target is given, the Target determined by default the default property of Project is executed by default. Basedir refers to a base path for other paths. Take a next? Please see the Properties property, a Project can have multiple Properties, a bit image definition variable, which is available for Task's attribute values. (Figure 1) If then when you use "$ {srcproperty}", the actual value is SRC. Below is Target, a Target can depend on other Targets. Here DIST is dependence, that is, executes Compile when performing DIST.

You can also write if or unless control statements, such as: , the Target will always be executed if there is no IF or UNLESS attribute. The above four Targets implemented (1) Creating a Build folder (2) Build file (3) Package. Jar (4) Clean up the work - Delete the folder. 3. Perform Targets Click on the Refresh button on the top left. A plus number will appear next to this icon. The following Targets you define will appear. Right click on Init, then select Make on the menu that is talked, so that this target creates a directory called Build. Then you can try it on other Tragets to see how to perform. Finally, execute the Clean Target clearly created directory. You can also click Right click directly on Build.xml, and you can execute the default target. Because the dist is depends on Compile, and Compile depends on init, it will execute a series of tasks that create a folder, reconfibrate file, and final package. 4. Use Ant to handle errors to open Application1.java, comment out of the main method - // public static void main (string [] args). Right-click Build.xml Select Make to compile, check the error message in the information panel, when double-clicked on the error message, the program panel automatically highlights the error. Remove // ​​in front of the main method to continue the following operations. (Fig. 2) 5. Add a target | Project property in the Project menu to select the build page after opening the Project Properties panel, then select the Menu Items page. Click the Add button in Menu Items Page (Figure 2), select the desired Ant Target after OK. In the Menu Items panel, you can adjust the location of the Ant Target in the right Move UP button and the Move Down button, and adjust the Clean to the second position here, click OK to close the Project Properties panel. At this point, you can see the item item under the Project menu, then click Clean to perform the delete folder task. 6. Set the ANT attribute to right-click Build.xml to select Properties. After taking the ANT page in the talked panel, set the log level to Verbose (Figure 3), which provides more detailed messages in the message panel. Click on the Add button on the right of Properties, select Build in the Name column in the pop-up window, and enter Test in the Value bar below. Click Two OK to close the two dialogs. Now when performing a compilation task, Ant is a folder that creates a TEST to put the class file here, not the previous build directory.

You can try it, right-click Compile Target, click Make, take a closer look, you will find more information, the specific information can be referred to: (Figure 3) Ant stdout apache ant version 1.5.1 Compiled on October 2 2002 BuildFile: build.xml Detected Java version: 1.4 in: H: /JBuilder7/jdk1.4/jre Detected OS: Windows 2000 parsing buildfile build.xml with URI = file: I: / personal / project / j_project / jbuilder_torial / AntProject / build. xml Project base dir set to: I: / personal / project / j_project / jbuilder_torial / AntProject Override ignored for property build Build sequence for target `compile 'is [init, compile] Complete build sequence is [init, compile, clean, dist] init: compile: [javac] antproject / Application1.java omitted as I: /personal/project/j_project/jbuilder_torial/AntProject/test/antproject/Application1.class is up to date [javac] antproject / Frame1.java omitted as I. : /personal/project/j_project/jbuilder_torial/antproject/test/antproject/frame1.class is up to date. [j AVAC] AVAC] ANTPROJECT / FRAME1.JBX SKIPPED - DON 'TOTAL TO HANDLE IT Build Successful Total Time: 1 SECOND Next, first select Project | Clean After clearing the directory, let's see how to set it in JBuilder when compiling. Compile with Ant to compile. Mark the mouse on ANTProject.jpx Select Clean, which is used to delete the class and class directory generated by jbuilder. Then select Properties after right-click Build.xml, select the always run ant when it buildings project is OK to close this dialog. Now, when you select Project | make Project, JBuilder automatically calls Ant to perform compilation tasks. If you need other class libraries when compiling, for example, you need to execute Java Mail, or JUnit test, you can join what you need: Choose Project | Project Properties, select the build page in the pop-up panel The ANT page, press Add to open a Select A Library Dialog window to increase the class library you need. If there is no desired class library in this window, you can click the New button to point to the lower left corner. Click After OK is turned off. You can adjust their sequence of lookup class libraries by Move Up or Move Down.

转载请注明原文地址:https://www.9cbs.com/read-109283.html

New Post(0)