Apache Maven 2 Effective Implementation Build and manage applications with Maven, Continuum, and Archiva Maria Odea Ching Brett Porter BIRMINGHAM - MUMBAI This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Apache Maven 2 Effective Implementation Build and manage applications with Maven, Continuum, and Archiva Copyright © 2009 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2009 Production Reference: 1080909 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847194-54-1 www.packtpub.com Cover Image by Vinayak Chittar ([email protected]) Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Credits Authors Editorial Team Leader Maria Odea Ching Gagandeep Singh Brett Porter Project Team Leader Priya Mukherji Reviewers Wendy Smoak Emmanuel Venisse Project Coordinator Leena Purkait Carsten Ziegeler Drawing Coordinator Acquisition Editor Nilesh Mohite Sarah Cullington Proofreader Development Editor Lesley Harrison Dhiraj Chandiramani Production Coordinator Technical Editors Shantanu Zagade Neha Damle John Antony Cover Work Shantanu Zagade Indexer Monica Ajmera Rekha Nair Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 About the Authors Maria Odea Ching grew up in Daet, a small town in the Philippines, then moved to the country's capital, Manila, when she went to college. She took up Computer Studies at De La Salle University, and graduated in 2004. She started using open source tools from her first job after graduating. From then on, she got interested in the open source philosophy. She was introduced to Apache Maven, Apache Continuum, and Apache Archiva early on in her career. She became a committer and a Project Management Committee member of Apache Maven. Eventually, she was elected as PMC Chair of Apache Archiva. She is also a member of the Apache Software Foundation. Deng is currently a Senior Software Engineer and serves as the development lead for the Maestro project. First, I'd like to thank Brett for the whirlwind endeavor which is this book. I'd also like to thank all our reviewers—Wendy, Emmanuel, Carsten and the Packt team, for taking the time to review and go through each chapter. You guys rock! And of course without the communities of Maven, Continuum, and Archiva, we wouldn't have anything to write about. So I'd like to thank each and everyone (committers/developers, contributors, buggers) in these respective communities. I'd also like to give special thanks to our Exist/G2iX family for their continuous support. And last but definitely not the least, I'd like to thank my family and my boyfriend, Mike, for their unfaltering love and support and for being so patient and understanding when I have to run off to work on the book. Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Brett Porter is a software developer from Sydney, Australia with a passion for development tooling and automation. Seeking a more standardized and reproducible solution to organize, build, and deploy a number of software projects across teams, he discovered an early beta of Maven 1.0 in 2003, and has been heavily involved in the development of the project since. He is a member of the Apache Maven Project Management Committee, and has conducted presentations and training on Maven and related tooling at several conferences and events. He founded the Archiva project in 2005. Brett is also a Director and Member of the Apache Software Foundation. Brett is currently VP, Product Development at G2iX, in charge of the MaestroDev division. He and his team seek to make developers more efficient by offering support and services for development and automation tools including Apache Maven, Apache Continuum, Apache Archiva, and Selenium. Brett was co-author of the book Better Builds with Maven, the first book to be written about the Maven 2.0 release in 2005, and has been involved in reviewing Maven: A Developer's Notebook and Java Power Tools. I'd first like to thank my co-author and friend Deng for agreeing to participate in this book and lending her experience with Archiva and Continuum. I am grateful to all of the reviewers that volunteered their time to help make this the best that it can be. My great thanks go to all the members of the open source community that participate in these projects—the developers, as well as those that contribute patches, detailed bug reports, or answer questions on the user lists—not only do we build great software together, but I get the chance to work with truly remarkable individuals. Finally, my love and thanks go to my wife Laura for sparing some more of our precious time so that I could complete this book, and for supporting me in everything I do. Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 About the Reviewers Wendy Smoak is a member of The Apache Software Foundation and a committer on several open source projects, where she focuses on user support, documentation, and infrastructure. By day she is a Solutions Architect with G2iX, where her work centers around enterprise adoption of Apache Maven and related technologies. Emmanuel Venisse has been developing and architecting J2EE applications for eleven years for bank, government, and holiday company projects. For the past three years, he's been working for Mergere/Devzuz with some other Maven contributors, like Brett and Deng, around a packaged Maven/Continuum/ Archiva product—Maestro. He has been working freelance for five years. For the last six years, he's been working, in his spare time, on Maven, Continuum, and Archiva projects as a core developer, and he's the Continuum project chair. He has contributed too to Maven: A Developer's Notebook (O'Reilly) and Better build with Maven (Exist). He lives in Versailles, France, with his wife Florence and two children. I would first like to thank my wife, Florence, without whose love and support, my work on Apache projects and this book wouldn't have been possible. I'd also like to thank my children who have to see their dad working on his laptop instead of playing with them. Finally, I'd like to thank Brett and Deng for letting me help them on this book. Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Carsten Ziegeler is senior developer and software architect for JEE and portal applications at Day Software. He is a member of the Apache Software Foundation and has been participating in several open source projects for more than fifteen years. Carsten is a member of several Apache communities and project management committees such as Cocoon, Felix, Sling, Excalibur, and Portals. In addition to this, Carsten frequently writes artcles, reviews books, and can be found presenting at various conferences. Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Table of Contents Preface 1 Chapter 1: Maven in a Nutshell 7 A whirlwind tour 7 Installing Maven 7 Creating a new project from an archetype 9 Building the project 15 Reusing builds 18 Adding dependencies 19 Adding functionality through plugins 22 Adding resources 27 Running tests 28 Getting help 32 Enhancing the development process 33 Viewing detailed project information 34 Multiple module builds 34 What if I need to convert an existing project? 35 Summary 35 Chapter 2: Staying in Control with Archiva 37 Importance of a repository manager 37 Installing Archiva 40 Separating your repositories 44 Hooking up Maven with Archiva 46 Setting up a proxy 46 Configuring your settings.xml 51 Building your project 52 Searching for artifacts in Archiva 55 Deploying from Maven 59 Creating a new user 60 Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090 Table of Contents Configuring and deploying from Maven 61 Deploying via web form 65 Summary 66 Chapter 3: Building an Application Using Maven 67 Introducing the sample project 67 Setting up a multi-module build 68 Creating the parent POM 69 Creating the modules 70 Dependency management 73 Fleshing out the example application 75 Creating an organization POM 76 Configuring basic reports 80 Preparing for non-code modules 82 Creating a modules tree 83 Adding a documentation module 85 Building the site automatically 88 Assembling the site for distribution 88 Adding site resources 90 Adding a skin 91 Distributing the application 93 Generating the runtime environment with the App Assembler plugin 95 Generating the assembly archive 99 Adding the documentation to the distribution archive 104 Summary 105 Chapter 4: Application Testing with Maven 107 Types of testing in Maven 108 Unit testing (or code testing) 108 Integration testing (or module testing) 109 Functional and other types of testing 109 Working with tests 110 Surefire plugin configuration 110 Controlling the execution of tests 111 Inclusion and exclusion of tests 112 Running specific tests from the command line 114 Skipping tests temporarily 115 Producing a report for the test results 115 Reviewing test coverage 117 Coverage and multimodule projects 123 Integration, functional, and other testing 124 Running integration tests using naming patterns 125 Operating the Selenium server 130 Deploying the application to a container 131 [ ii ] Download at WoWeBook.Com This material is copyright and is licensed for the sole use by David Martone on 16th September 2009 710 South Avenue West, , Westfield, , 07090
Description: