When you are used to build your projects with ant a switch to maven can be quite confusing. Maven works in a different way.
ant
Ant is quite easy to understand and gets you started right a way. You can script from target to target and when you want to preform more complex tasks you can configure your own macro’s with the libraries you want to use.
maven
maven works differently. It uses build faces that are processed depending on the artifact type. With plugins you can connect functionality to different phases, this depends on the plugin that has been defined. Some plugins like maven-surefire-plugin are connected by default to a phase (in this example test) other plugins can be configured on multiple phases. For every phase you specify the goal that has to be executed and that’s the method that will be preformed in that phase. In this example is the goal test of the surefire plugin
lifecycle
example:
for a jar artifact the following phases are executed:
- process-resources
- compile
- process-test-resources
- test-compile
- test
- package
- install
- deploy
the default life cycle is as followed:
- validate
- initialize
- generate-sources
- process-sources
- generate-resources
- process-resources
- compile
- process-classes
- generate-test-sources
- process-test-sources
- generate-test-resources
- process-test-resources
- test-compile
- process-test-classes
- test
- prepare-package
- package
- pre-integration-test
- integration-test
- post-integration-test
- verify
- install
- deploy
using the test phase
When you have made some junit test to verify the working of your code you would like that they are executed during the test phase in the building lifecycle. To do this you have to include the maven-surefire-plugin
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <includes> <include>**/unit/*.java</include> </includes> </configuration> </plugin>
Default the maven-surefire-plugin connects to the test phase and when i call the maven fase package
mvn package
maven compiles the code and before it creates the package i see that the unit tests in my unit directory are executed.
For more information about the maven lifecycle check apache.org. And read carefully the documentation of the plugin to see when it executes and to what phases you can bind the plugin.
Welcome to the world of maven.
Popularity: 1% [?]
Theo van Arem is a Integration specialist working at 

