Previous – Chapter 8

Maven Tutorial – Chapter 9

In the previous project, we have seen how to create sample maven project using maven archetype and understood how the folder structure is organized. This chapter will cover building and testing the maven project created in previous chapter.

Building the project
once the coding is completed in the project, the project needs to be compiled, built and make it to be ready for the deployment. To achieve this, navigate to the root project folder where it consists of the pom.xml file. E.g. D:\Java\workspace\JavaSamples. Now, type the command mvn package and enter. This command will invoke the maven package phase. As explained here, whenever a maven phase is invoked, it executes in a sequence up to and the invoked phase. Hence, in this case the phases above package – validate, compile and test phases will be executed.

img_1
img_2When mvn package command is run, maven will validates and compile the source code, execute the junit test cases and packs/bundles it as per the instructions given in the tag <packaging> in the pom.xml file. If the packaging is specified as “jar”, then a jar with the package will be created.

img_3

To run the App.test java, open the command prompt and navigate to the folder D:\Java\workspace\JavaSamples\target\classes and enter the command
java com.java.samples.App

img_4

To run the test classes (junits), open the command prompt and from the root folder of the project, execute the command mvn test

img_5

 

img_6

 Next – Chapter 10

Leave a Reply

Your email address will not be published. Required fields are marked *