Java | Few tips about Maven

Author - Rita
13.02.2017
|
0 Comments
|

1.  How to compile maven project using different poms?

Solution: When we start compiling project with mvn -clean install command, maven tool first attempts to search the pom.xml file in the current directory. If no pom is found in the current directory then it will show following error message:

[INFO] Scanning for projects…
[INFO] ————————————————————————
[INFO] BUILD FAILURE
[INFO] ————————————————————————
[INFO] Total time: 0.103s
[INFO] Finished at: Mon Nov 07 14:58:00 IST 2016
[INFO] Final Memory: 5M/148M
[INFO] ————————————————————————
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/var/www/html/your_project ). Please verify you invoked Maven from the correct directory. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]

By default, maven tool will search for pom.xml file during compilation in the current directory. If you want to use more than one pom file, create more than one xml files with different names like pom1.xml, pom2.xml etc.

Run following command:

Command : mvn -DskipTests clean install -f pom1.xml -to compile using pom1.xml
mvn -DskipTests clean install -f pom2.xml -to compile using pom2.xml

If your project module are dependent on one another then follow the correct order with respect to your project dependency.

2. How to skip tests during maven compilation?

Solution: Default directory structure for a maven web application is:

1
Fig1: maven directory structure

All unit tests will go to the src/test/java directory. When we will start compiling the project, it will compile and run all the tests by default. Any error in the test compilation/test run will not allow you to go further. It will stop compiling process and throw errors in the output. If you want to skip test compilation, use the following switch in the compilation command:

Switch: DskipTests.
Command: mvn -DskipTests clean install;

Above command will skip all the tests run during compilation time.

3.  How to compile maven project in debug mode?

Solution: To compile maven project in debug mode, use the following switch with maven compilation command:

Switch: debug
Command: mvn –debug clean install;

If you want to run your project in debug mode and wants to use a breakpoint, do following:
Compile your project in debug mode.
Start tomcat server in debug mode.
Add breakpoints on required locations.
Deploy your project and do testing. JVM runtime will automatically detect your breakpoints and show output accordingly.

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

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