Apache Maven 3 Cookbook Over 50 recipes towards optimal Java software engineering with Maven 3 Srirangan BIRMINGHAM - MUMBAI Apache Maven 3 Cookbook Copyright © 2011 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 author, 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: August 2011 Production Reference: 1180811 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-849512-44-2 www.packtpub.com Cover Image by Parag Kadam ([email protected]) Credits Author Project Coordinator Srirangan Michelle Quadros Reviewer Proofreader Carsten Ziegeler Lisa Brady Emmanuel Venisse Indexer Acquisition Editor Hemangini Bari Sarah Cullington Graphics Development Editor Nilesh Mohite Chris Rodrigues Production Coordinator Technical Editor Aparna Bhagat Priyanka S Cover Work Copy Editor Aparna Bhagat Leonard D’Silva About the Author Srirangan is a passionate programmer with nine years of experience in freelance, open source, and Enterprise. He has executed projects in a broad range of technologies including Python, PHP, Scala, Java, Adobe Flex, HTML5, Javascript, and so on. He is the creator of Review19 (http://www.review19.com); an innovative, real-time Agile team collaboration and project management tool. He is also involved with India Defence (http://www.indiadefence.in) which is India's largest web property dedicated to the defense sector. Sri is a senior consultant in Inphina Technologies (http://www.inphina.com), a rapidly expanding, high-end technology startup in New Delhi focusing on cloud computing (Google App Engine, Hadoop) and emerging technologies. He is an enthusiastic open source contributor and his open source projects are available on GitHub and BitBucket: https://github.com/Srirangan https://bitbucket.org/srirangan To know more you can also visit the following links: Blog - http://srirangan.net Twitter - http://twitter.com/srirangan LinkedIn - http://www.linkedin.com/in/srirangan About the Reviewer Carsten Ziegeler is a senior developer and software architect for JEE and portal applications at Adobe Systems. He is a member of the Apache Software Foundation and has been participating for more than twenty years in several open source projects. Carsten is a member of several Apache communities and project management committees like Felix, Sling, and Portals. In addition, Carsten is frequently writing articles, reviewing books, and presenting at various conferences. Emmanuel Venisse has been developing, architecturing, and integrating J2EE applications for thirteen years for banks, government, holiday company projects, and so on. For the last six years, he has worked as a freelancer. For the last eight years, he's been working, in his spare time, on Apache Maven, Continuum and Archiva projects as a core developer and he's also the Continuum project leader. He has contributed to the majority of books written about Apache Maven. www.PacktPub.com Support files, eBooks, discount offers and more You might want to visit www.PacktPub.com for support files and downloads related to your book. Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at [email protected] for more details. At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks. http://PacktLib.PacktPub.com Do you need instant solutions to your IT questions? PacktLib is Packt’s online digital book library. Here, you can access, read and search across Packt’s entire library of books. Why subscribe? f Fully searchable across every book published by Packt f Copy and paste, print and bookmark content f On demand and accessible via web browser Free access for Packt account holders If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access. Table of Contents Preface 1 Chapter 1: Basics of Apache Maven 7 Setting up Apache Maven on Windows 8 Setting up Apache Maven on Linux 11 Setting up Apache Maven on Mac 12 Verifying the Apache Maven installation 13 Creating a new project 14 Compiling and testing a project 17 Understanding the Project Object Model 19 Understanding the build lifecycle 21 Understanding build profiles 22 Chapter 2: Software Engineering Techniques 25 Build automation 26 Project modularization 28 Dependency management 31 Source code quality checks 34 Test Driven Development 37 Acceptance testing automation 40 Deployment automation 44 Chapter 3: Agile Team Collaboration 47 Creating centralized remote repositories 48 Performing continuous integration with Hudson 54 Integrating source code management 57 Team integration with Apache Maven 60 Implementing environment integration 64 Distributed development 67 Working in offline mode 69 Table of Contents Chapter 4: Reporting and Documentation 73 Documenting with a Maven site 74 Generating Javadocs with Maven 77 Generating unit test reports 81 Generating code coverage reports 85 Generating code quality reports 87 Setting up the Maven dashboard 90 Chapter 5: Java Development with Maven 95 Building a web application 96 Running a web application 100 Enterprise Java development with Maven 102 Using Spring Framework with Maven 106 Using Hibernate persistence with Maven 112 Using Seam Framework with Maven 119 Chapter 6: Google Development with Maven 125 Setting up the Android development environment 126 Developing an Android application 128 Testing and debugging an Android application 132 Developing a Google Web Toolkit application 134 Testing and debugging a Google Web Toolkit application 139 Developing a Google App Engine application 142 Chapter 7: Scala, Groovy, and Flex 147 Integrating Scala development with Maven 148 Integrating Groovy development with Maven 153 Integrating Flex development with Maven 156 Chapter 8: IDE Integration 163 Creating a Maven project with Eclipse 3.7 164 Importing a Maven project with Eclipse 3.7 168 Creating a Maven project with NetBeans 7 172 Importing a Maven project with NetBeans 7 177 Creating a Maven project with IntelliJ IDEA 10.5 179 Importing a Maven project with IntelliJ IDEA 10.5 183 ii Table of Contents Chapter 9: Extending Apache Maven 187 Creating a Maven plugin using Java 188 Making your Java Maven plugin useful 192 Documenting your Maven plugin 196 Creating a Maven plugin using Ant 198 Creating a Maven plugin using JRuby 200 Index 203 iii
Description: