MAVEN IN ACTION PDF

adminComment(0)

Installing Maven on Linux, BSD or Mac OSX. Most of the action in Maven happens in plugin goals which take care of things like. Universal Reuse Through Maven Plugins. 5 Optimizing with the Maven Dependency Plugin. .. Most of the action in Maven happens in. Installing Maven on Linux, BSD and Mac OS X.. outline the recommended best-practice for installing Maven on a variety of operating systems.


Maven In Action Pdf

Author:AMINA JACKOWSKI
Language:English, Portuguese, Hindi
Country:Cyprus
Genre:Politics & Laws
Pages:704
Published (Last):12.05.2016
ISBN:542-3-58329-113-7
ePub File Size:19.39 MB
PDF File Size:14.78 MB
Distribution:Free* [*Registration Required]
Downloads:43823
Uploaded by: LAKESHIA

Need Maven to build a project you have downloaded? Read our Quick Start guide on how to get and use Maven for a project that is already set. If you are working in Java for a couple of years you surely know about Maven, the This book is available to download in PDF format as well for online reading. Maven is largely replacing Ant as the build tool of choice for large open source Java Inc.; 1 edition (May 11, ); Paperback: pages; eBook PDF, MB .

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.

7 Best Maven Books

You can upgrade to the eBook version at www. At www. Why subscribe? Simply use your login credentials for immediate access. When positioned at the very heart of your development strategy, Apache Maven can become a force multiplier not just for individual developers but for Agile teams and managers. The Apache 3 Maven Cookbook is a real-world collection of step-by-step solutions for individual programmers, teams, and managers to explore and implement Apache Maven and the engineering benefits it brings into their development processes.

This book helps with the basics of Apache Maven and with using it to implement software engineering best practices and Agile team collaboration techniques. It covers a broad range of emergent and enterprise technologies in the context of Apache Maven, and concludes with recipes on extending Apache Maven with custom plugins.

The book is rounded off by exploring how to extend the Apache Maven platform by building custom plugins, integrating them with existing projects, and executing them through explicit command-line calls or with Maven build phases. What this book covers Chapter 1, Basics of Apache Maven, assists you while you take your first steps with Apache Maven.

It will cover setting up Apache Maven on your operating system, verifying the setup, and getting started with your first Apache Maven project. Chapter 2, Software Engineering Techniques, introduces us to implementing software engineering best practices and techniques such as Test Driven Development, build automation, dependency management, and so on with Apache Maven.

Preface Chapter 3, Agile Team Collaboration, helps you implement collaboration mechanisms with Apache Maven that aid team and distributed development. Chapter 4, Reporting and Documentation, helps you generate reports and documentation, code quality, test coverage reports, and other related metrics and bundles them in a Maven site. Chapter 5, Java Development with Maven, helps you take on web application and enterprise application development challenges with Java while leveraging popular frameworks including Spring and Hibernate.

Chapter 7, Scala, Groovy, and Flex, discusses these popular upcoming technologies and frameworks and gets you started on these with Apache Maven. Recipes in the first chapter guide you on how to set up the Java SDK on your machine. Other than this, Apache Maven automatically downloads all dependencies during execution. Make sure you have fairly good internet access available while working with Apache Maven.

Who this book is for This book is for Java developers, teams, and managers who want to implement Apache Maven in their development process, leveraging the software engineering best practices and Agile team collaboration techniques it brings along. The book is also specifically for the developer who wishes to get started in Apache Maven and use it with a range of emergent and enterprise technologies including Enterprise Java, Frameworks, Google App Engine, Android, and Scala.

Here are some examples of these styles, and an explanation of their meaning. Code words in text are shown as follows: "The archetype: generate command would have generated a sample Apache Maven project for us". Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Enter the administrative Username and Password.

Tips and tricks appear like this. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of. Customer support Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your download.

Errata Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book.

Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

We appreciate your help in protecting our authors, and our ability to bring you valuable content. Its formative years were then spent in the Apache Turbine project where it eventually came to replace a brittle and fragile build system based on Apache ANT.

In recent years, Maven has clearly emerged as an important force-multiplier for Agile teams and organizations.

In the upcoming recipes, we will set up Maven on various platforms and host environments followed by selectively exploring the core concepts of the Project Object Model and the Maven build lifecycle.

Maven is a command-line tool and needs to be integrated with the Windows environment variables. The process is quite simple and Java dependent. There is a chance Apache Maven may have been pre-installed on your machine. See the recipe Verifying the Maven installation in this chapter Getting ready As mentioned, a prerequisite for working with Maven is the availability of the Java Development Kit.

Make sure that the JDK is available before proceeding.

Apache Maven 3 Cookbook

This can be verified by running the following command line: Java -version It will give the following output: java version "1. Got JDK? Next you need to get your hands on Maven. I extracted Maven in the D drive. To start using Maven, we need to configure Windows environment variables.

You can set the environment variables by accessing the System settings in the Control Panel. The PATH environment variable will already exist. Select it and click Edit to modify. It is also available for integration with IDEs and other development tools, but more on that in upcoming chapters.

If you use any other Linux distribution, the steps should nevertheless remain similar. See the recipe Verifying the Maven installation in this chapter Getting ready A prerequisite for working with Maven is the availability of the Java Development Kit. Make sure the JDK is available before proceeding.

This can be verified by running the command line: java -version It should give the following output: java version "1. After downloading Maven, extract the archive into a folder. This will be an installation for a single user. How to do it See the recipe Verifying the Maven installation in this chapter Getting ready A pre-requisite for working with Maven is the availability of the Java Development Kit.

This can be verified by running the following command line: java -version It should give the following output: java version "1.

Alternatively, your operating system may have Apache Maven pre-installed. Before you start using it, the setup and availability of Maven needs to be verified.

This is done by executing the following command line: mvn -version ff If Maven has been correctly installed, you will see something resembling the following output: Apache Maven 3. See also ff Creating a new project in this chapter Creating a new project All done with downloads, setups, configurations, installations, and verifications? If not, refer to the first few recipes of this chapter.

In this recipe, we will create our first Apache Maven project. To be more specific, we will use the Maven archetype:generate goal to generate our first Maven Java project.

Then we take a look at the Maven project structure to get an idea of what constitutes a Maven project and what goes where by convention. For now, select the default archetype. Here we have considered that it is archetype number named maven-archetype-quickstart.

Using maven-archetype-quickstart org. GroupId co-ordinates are used to specify the hierarchical location of a project within a Maven repository. In this case, the repository is the local Maven repository present in your filesystem. GroupId co-ordinates are typically the root package and thus can be shared by multiple projects within an organization. The artifactId is an identifier for your project and version here refers to the project version.

Packages refer to the reverse dns root package name that is commonly used in Java and a host of other programming languages. We just asked Maven, actually a Maven plugin, to create or rather generate a new project for us. A new project for Apache Maven can either be "hand-crafted" with manual pom. Simple answer—the following: -- pom. These then contain the complete package structure and a sample application with a unit test case. Getting ready ff Start your command-line terminal window ff Navigate to the project folder that contains the pom.

Test Driven Development TDD is a popular practice that is advocated for and followed religiously by some of the very best software craftsmen in the industry. Maven, having recognized this, makes testing part of the default build lifecycle. This makes TDD easier for teams who are trying to implement it in their development process. Run the following command to run the tests: mvn test This command triggers Maven to run the tests present in the By default, it is set to JDK1.

The compiled code is placed in the "target" directory. The target directory will contain the compiled artifact that is, a JAR file for a Java project by default along with directories for compiled classes and tests. It will further contain the pom.

The pom. This includes project configuration, defect tracking system details, project organization and licenses, project paths, dependencies, and so on.

You might also like: JUNIT IN ACTION PDF

Project co-ordinates Project co-ordinates are the minimal basic fields that a POM definition must contain. The three co-ordinate fields are groupId, artifactId, and version.

These three fields mark a specific location within the repository, hence the term co-ordinates. They are explained as follows: ff The basics: This section contains project co-ordinates, dependency management, and inheritance details. Additionally, it also contains modules and project level properties. See also ff Understanding the build lifecycle in this chapter ff Understanding build profiles in this chapter 20 Chapter 1 Understanding the build lifecycle The build lifecycle explicitly defines the process of building, testing, distributing an artifact, and is at the heart of every Maven project.

There are three inbuilt build lifecycles: default, clean, and site. Default lifecycle The default lifecycle handles the project compilation, test, and deployment. While it contains over 20 build phases, the following are the most important phases: ff Validate: validates that all project information is available and is correct ff Compile: compiles the source code ff Test: runs unit tests within a suitable framework ff Package: packages the compiled code in its distribution format ff Integration-test: processes the package in the integration-test environment ff Verify: runs checks to verify that the package is valid ff Install: installs the package in the local repository ff Deploy: installs the final package in a remote repository Whenever you execute a build phase, all prior build phases are executed sequentially.

Hence, executing mvn integration-test will execute the validate, compile, test, and package build phases before executing the integration-test build phase.

This is done by allowing configuration within the POM, avoiding all filesystem references, and depending extensively on the local repository to store the required metadata. For these cases, Maven introduces the concept of build profiles.

Top 5 Apache Maven Free Ebooks for Java Developers

Build profiles are specifications made in the POM and can be triggered as and when required. Some ways to trigger profiles are: ff Explicit command-line trigger ff Maven settings trigger ff Environment specific trigger Explicit command-line trigger Profiles can be directly triggered through the command line using the -P option. The list of profiles, separated by commas, that are to be activated should be mentioned after the -P flag: mvn install -P profile-1,profile-2 In this case, only the profiles explicitly mentioned in the command will be activated and all other profiles stay dormant for this build.

The reverse is possible as well. You can explicitly specify which profiles should not be activated through the command line: mvn install -P!

Environment specific trigger Profiles can also be triggered based on the current build environment. The environment in which the profile is to be activated is directly defined within the POM profile declarations. The benefits, trade-offs, and pros and cons of these practices are well-known and will only need little mentioning. These practices are not inter-dependent, but some of them are inter-related in the larger scheme of things.

One such example would be the relation between project modularization and dependency management. While nothing stops either from being implemented in isolation, they are more beneficial when implemented together. These techniques can be further supplemented by the industry's best practices such as continuous integration, maintaining centralized repositories, source code integration, and so on, which will be studied in detail in Chapter 3, Agile Team Collaboration.

Our focus here will be on steadily understanding these software engineering techniques within the context of Maven projects and we will look at practical ways to implement and integrate them. Software Engineering Techniques Build automation Build automation is the scripting of tasks that software developers have to do on a day-to-day basis.

These tasks include: ff ff ff ff ff Compilation of source code to binary code Packaging of binary code Running tests Deployment to remote systems Creation of documentation and release notes Build automation offers a range of benefits including speeding up of builds, elimination of bad builds, standardization in teams and organizations, increased efficiency, and improvements in product quality. Today, it is considered as an absolute essential for software engineering practitioners.

Getting ready You need to have a Maven project ready. The archetype:generate command would have generated a sample Apache Maven project for us. Follow the steps given next to validate the same: 1. Start the command-line terminal and navigate to the root of the Maven project. You just triggered some of the phases of the build life cycle by individual commands. Maven lets you automate the running of all the phases in the correct order. Just execute the following command, mvn install, and it will encapsulate much of the default build lifecycle including compiling, testing, packaging, and installing the artifact in the local repository.

How it works For every Apache Maven project, regardless of the packaging type, the default build lifecycle is applied and the build is automated. As we just witnessed, the default build lifecycle consists of phases that can be executed from the command-line terminal.

These phases are: ff Validate: Validates that all project information is available and correct ff Compile: Compiles the source code ff Test: Runs unit tests within a suitable framework ff Package: Packages the compiled code in its distribution format ff Integration-test: Processes the package in the integration test environment ff Verify: Runs checks to verify if the package is valid ff Install: Installs the package in the local repository ff Deploy: Installs the final package in a remote repository Each of the build lifecycle phases is a Maven plugin.

Maven build automation also pushes for standardization among different projects within an organization, as the commands to execute build phases remain the same. See also ff The project object model section in Chapter 1, Basics of Maven ff Test driven development section in Chapter 2, Software Engineering Techniques ff Deployment automation section in Chapter 2, Software Engineering Techniques Project modularization Considering that you're building a large enterprise application, it will need to interact with a legacy database, work with existing services, provide a modern web and device capable user interface, and expose APIs for other applications to consume.

It does make sense to split this rather large project into subprojects or modules. Apache Maven provides impeccable support for such a project organization through Apache Maven Multi-modular projects. The parent project's POM file contains references to all these sub-modules. Each module can be of a different type, with a different packaging value.

Remember to set the value of packaging to pom, as highlighted in the following code: 4. It doesn't contain any sub-modules for now. You can pick archetype number , maven-archetype-quickstart, which generates a basic Java project.

The archetype:generate command also requires you to fill in the Apache Maven project co-ordinates including the project groupId, artifactId, package, and version. After project generation, inspect the POM file of the original parent project.

You will find the following block added: moduleJar The sub-module we created has been automatically added in the parent POM.

Maven Website

It simply works—no intervention required! Compiling and installing both sub-modules in the correct order in case sub-modules are interdependent is essential. In Multi-modular projects, where dependencies can run into tens or even hundreds, Apache Maven excels in allowing you to retain a high degree of control and stability. Apache Maven dependencies are transient, which means Maven will automatically discover artifacts that your dependencies require.

This feature has been available since Maven 2, and it especially comes in handy for many of the open source project dependencies we have in today's enterprise projects.

System Requirements and Supported Platforms

Getting ready Maven dependencies have six possible scopes: ff Compile: This is the default scope. Compile dependencies are available in the classpaths. Jason Van Zyl is the inventor and lead developer of Maven.

Book Site. Title Maven: O'Brien, Sonatype Company Publisher: O'Reilly Media, Inc. English ISBN Book Description For too long, developers have worked on disorganized application projects, where every part seemed to have its own build system, and no common repository existed for information about the state of the project. The second part offers a complete reference guide that includes: Reviews, Ratings, and Recommendations: site Related Book Categories: The Definitive Guide Timothy M.

The How-to Guide for Maven 2. All Categories. Recent Books. IT Research Library. Miscellaneous Books. Computer Languages. Computer Science. Electronic Engineering. Linux and Unix.Here is an example: mvn package This example executes the package build phase, and thus also all build phases before it in Maven's predefined build phase sequence.

Mention the dependency in your POM: junit junit 4. This can be done by selecting Manage Hudson Configure System. Sonatype, the company behind Nexus open source repository manager and creators of Apache Maven project provides a couple of good free ebooks to learn Maven and Nexus repository. Instead of constantly updating the version numbers to get the latest version, you can depend on a snapshot version of the project.

See the recipe Verifying the Maven installation in this chapter Getting ready As mentioned, a prerequisite for working with Maven is the availability of the Java Development Kit. Each dependency is described by its groupId, artifactId and version. Tips and tricks appear like this. Additionally, it also contains modules and project level properties.

BRANDEE from Burlington
See my other articles. I have a variety of hobbies, like hiking. I fancy studying docunments zestily.
>