Once you create a variable like this, you can use it to represent your classpath during a later compile task, which I'll demonstrate shortly. Before I get into the compile task, I want to note that another nice thing this syntax does is include jar files that are in subdirectories of your lib directory in the classpath.
I like this, because then I can keep all my Apache jar files in one subdirectory, and my database jar files in another subdirectory, and other jar files like JUnit and Cobertura in another subdirectory, etc. Once you've created a classpath variable as shown above, compiling your Java application from your Ant build script is straightforward.
Just create a compile target that invokes the javac task, and give the javac task the classpath variable you created earlier, in my case build. This compile target compiles all the files found in the src directory, using the classpath we created, and puts the output, compiled files in the classes directory.
Let's say that you want to use the a global classpath reference. How is it helpful?. Also the below blocks. Please explain in detail. Why do we use the above path tags?. You usually use the same classpath in different tasks, so instead of setting in every task, you can declare it globally like that, using the path tag, and refer to it from targets and tasks.
Please refer to the online manual for details about the java task. I've already posted the link in my previous post. The example here simply says : "use the classpath defined in project. More comfortable would be using a property file. In the Java source file, delete the BasicConfiguration line from the main method and the related import statement. Log4J will search then for a configuration as described in its manual.
That's the default name for Log4J's configuration and using that name would make life easier—not only the framework knows what is inside, you too!
We should deliver the configuration file, too. So we change the buildfile:. This copies all resources as long as they haven't the suffix. In this step we will introduce the usage of the JUnit [3] test framework in combination with Ant. Because Ant has a built-in JUnit 4.
Because we don't have real business logic to test, this test class is very small: just showing how to start. For further information see the JUnit documentation [3] and the manual of junit task. Now we add a junit instruction to our buildfile:. We reuse the path to our own jar file as defined in run -target by giving it an id and making it globally available.
How much tests failed? Some errors? The classpath is set up to find our classes. This is a common naming scheme. We can also produce a report. Something that you and others could read after closing the shell There are two steps: 1. The log format is XML so junitreport could parse it.
0コメント