ANT NetBeans should be installed to run a project. The following topics are covered in ANT NetBeans chapter:
Running Java Code
Running Project
Description
Sending mails is the last process. Before sending, one has to stop report recording process as it depends on halting the recorder.
If they are multiple files, users need to zip the files to send along with the files of the report directory. And, the file name should be same as of the project name.
SMTP server is required to use mail task, which defines the host machine where host address, date, from/to addresses can be included.
Take sample java code and name it as TestMath.java, Math.java and HelloWorld.java. All these files are to be created under src folder.
Examples
TestMath.java
[java]
import junit.framework.*;
public class TestMath extends TestCase {
public void testAdd() {
int num1 = 3;
int num2 = 2;
int total = 5;
int sum = Math.add(num1, num2);
assertEquals(sum, total);
}
public void testMulitply() {
int num1 = 3;
int num2 = 7;
int total = 21;
int sum = Math.multiply(num1, num2);
assertEquals("Problem with multiply", sum, total);
}
}[/java]
Math.java
[java]
public class Math {
static public int add(int a, int b) {
return a + b;
}
static public int multiply ( int a, int b) {
return a * b;
}
}[/java]
HelloWorld.java
[java]
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, world!");
System.out.println(args[0]);
}
}[/java]
NetBeans Integration
Description
Build the project in NetBeans by creating a new project. The code will look like:
As soon as the xml is run, build directory and report directory will be created and the following output will appear:
Step-3
Next, run the compiler target similar to the process shown above for the prepare task. As soon as the compiler code is run, the following files will be created as shown in figure:
The following output can be seen:
As CVS server is not used here, console displays the output of fetch task.
Step-4
Then, run the test target and the output will be as follows.
Step-5
Run the war target and the output will appear as follows:
The war file appears with the project name and date.
Step-6
Finally, run the sendmail target and check the email in the given email id. The following output appears while deploying into the server and sending the mail. Simultaneously, recorder will be stopped.
Step-7
Final build report will be sent to the given mail and test results will be displayed as shown below.
Summary
Key Points
Java codes are placed in src folder.
When xml file is run, build and report directories are created automatically.