Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Apache Maven Cookbook

You're reading from  Apache Maven Cookbook

Product type Book
Published in Apr 2015
Publisher Packt
ISBN-13 9781785286124
Pages 272 pages
Edition 1st Edition
Languages

Table of Contents (18) Chapters

Apache Maven Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Getting Started 2. IDE Integration with Maven 3. Maven Lifecycle 4. Essential Maven Plugins 5. Dependency Management 6. Code Quality Plugins 7. Reporting and Documentation 8. Handling Typical Build Requirements 9. Multi-module Projects 10. Java Development with Maven 11. Advanced Maven Usage Index

Building a simple project with Maven


Let us now build the project that was created in the preceding section.

How to do it...

To build the previously created simple project with Maven, perform the following steps:

  1. Open the command prompt and run the following command, changing the directory to the folder the project was created:

    mvn package
    
  2. Observe the following things in the output:

    Notice the following warning (we will see how to resolve this later in this book):

    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ simple-project ---
    [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
    i.e. build is platform dependent!
    

    Check if the sources are compiled:

    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ simple-project
    

    Check if the tests are run:

    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ simple-project ---
    [INFO] Surefire report directory: C:\projects\apache-maven-cookbook\simple-project\target\surefire-reports
    -------------------------------------------------------
     T E S T S
    -------------------------------------------------------
    Running com.packt.cookbook.AppTest
    Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.005 sec
    
  3. A JAR file is now created.

How it works...

In the mvn package command, the package parameter is a phase in the build lifecycle. Maven has a default build lifecycle that has a number of phases. Each phase will execute every phase prior to it in order along with the specified phase. In this case, the package phase executes in the following order:

  • Validate

  • Compile

  • Test

  • Package

The validate phase makes sure that the project (specifically the pom.xml file that describes the project) is in order and all the necessary information to run the project is available.

The compile phase compiles the sources.

The test phase compiles the test sources and then runs the test using a suitable test framework. In the earlier example, the JUnit framework is used to run the tests.

The package phase packages the artifacts to the format specified in the pom.xml file.

You have been reading a chapter from
Apache Maven Cookbook
Published in: Apr 2015 Publisher: Packt ISBN-13: 9781785286124
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}