- Overview
-
Table of Contents
- J2SE: Standard Java
- Java Windows NT Services
- Apache Velocity
- Advanced J2SE
- Bytecode Instrumentation
- Dynamic Languages and the JVM
- J2SE 1.5.0: "Tiger"
- Java SE 6
- Java 7
- Core Computer Science Principles in Java (Data Structures)
- Annotations
- Java Generics
- Java New I/O
- Java Sound
- Java Applets
- JavaFX
- Java SE Threading
- Resource Management Using Semaphores
- Java Atomic Operations
- JavaTemplate Pages
- Executing Templates with the JtpExecutor
- Java Cryptography Extensions (JCE)
- Java Database Connectivity (JDBC) API
- Jakarta Commons - Net Class Library
- Jakarta Commons HttpClient
- Apache POI
- Regular Expressions
- JavaMail
- Cool Tools
- Building an Really Simple Syndication (RSS) Java App
- Embedding JavaScript in Java with Rhino
- Logging with Log4J
- Inside Swing
- Swing Components
- SwingX
- Swing Styled Documents
- Web Rendering in Java Swing Applications
- Java Look-and-Feel Graphics Repository
- Java Media Framework
- Quicktime for Java
- Media in Java Review 2008
- External Multimedia in Java
- Graphs and Charts
- Holiday Special: Electronic Greeting Card
- Media Framework: Presenter Application
- Standard Widget Toolkit
- JFace
- Java Performance Tuning
- J2EE Performance Tuning
- Caches and Pools
- Java Caching System
- EHCache
- Java Compression and Decompression
- Obfuscating Java Applications
- Continuous Integration
- Load Testing
- Tomcat Clustering
- High Scalability with Terracotta
- Troubleshooting Production Performance Issues
- Enterprise Java Testing
- Automated Unit Testing with JUnit and Ant
- Unit Testing: Tips From The Trenches
- Custom Ant Tasks
- Extensible Markup Language (XML)
- Java Web Technologies
- Web Frameworks
- Struts 2
- Wicket
- JavaServer Faces
- Distributed Programming / RMI
- Behavior Tracking Servlet Filter
- Servlet Filters
- Building a Robust Java Server
- J2EE: Enterprise Java
- Spring
- Spring 3
- Java Design Patterns
- Model-Driven Architecture
- Enterprise Messaging with ActiveMQ
- Event-Driven Architecture
- XDoclet
- Hibernate
- Developing Standalone Database Applications with Hypersonic DB
- Project Backup
- J2EE Project: Hands-On
- Enterprise Java Beans (EJB) 3.0
- Disaster Recovery
- Java Management Extensions (JMX)
- Service-Oriented Architecture
- Web Services
- RESTful Web Services
- Web Services with Apache CXF
- Atom Syndication
- Project: Building a Web Photo Gallery
- J2ME: Micro Java
- Specialized J2ME
- Optional Packages
- Other Java Technologies
- Derivatives and Competitors
- Java, Engineered for Integration
-
Additional Resources
- The World of Java Tools
- Building Java Applications with Ant
- Managing Java Build Lifecycles with Maven
- Acceptance Testing with FitNesse
- Source Control with Subversion
- Inversion of Control and Dependency Injection
- Certification
- Roadmap: Becoming an Enterprise Java Developer
- Roadmap: Becoming an Enterprise Java Developer in 2007
- The Business of Enterprise Software
- JavaOne 2006
- JavaOne 2007
- JavaOne 2008 Wrap-Up
- JavaOne 2009 Wrap-Up
- JavaOne 2010
- JavaOne 2011
- How to Survive in a Turbulent Job Market
- How to Hire the Best Talent
- Unified Modeling Language (UML)
- Cloud Computing
- Amazon EC2 and Java
- MongoDB
- Enterprise Java in 2008 and Beyond
- Predictions for 2018
Managing Java Build Lifecycles with Maven
Last updated Mar 14, 2003.
You’ve undoubtedly heard me talk about two primary contenders in the Java build tool space: Ant and Maven, but in actuality categorizing Maven as simply a build tool is doing it a disservice. Maven should rather be categorized as a project management or a project lifecycle management tool. Maven is meant to take control of the building, testing, and packaging of your application: your responsibility is to describe your project to Maven and its job is to manage its build lifecycle. The process of describing your project involves defining a project management file, called a POM file, placing resources in the appropriate locations, and telling Maven about dependencies upon which your application depends.
Probably the best known feature of Maven is its dependency management and its support for distributed repositories. In short, you tell Maven what libraries your application uses, such as Hibernate version 3.3.2 or Spring version 2.5.6 and it goes to the Internet to one of its repositories, downloads the correct versions of JAR files, and then compiles your application with those JAR files. Furthermore, if you are building a WAR or EAR file, it builds those artifacts with the included dependencies in the correct locations, for example it places JAR files in the WEB-INF/lib folder in the case of a WAR file. And if that were not easy enough, you only need to know about the dependencies that you need, not the dependencies that your dependencies need (because Maven finds those recursively.)
With respect to lifecycle, Maven forces you to think more in terms of lifecycle phases than in terms of tasks that you want to accomplish. For example, the following are the default lifecycle build phases that Maven lists on its website (which is really a subset of the complete lifecycle listed here)
- validate: validate the project is correct and all necessary information is available
- compile: compile the source code of the project
- test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed
- package: take the compiled code and package it in its distributable format, such as a JAR.
- integration-test: process and deploy the package if necessary into an environment where integration tests can be run
- verify: run any checks to verify the package is valid and meets quality criteria
- install: install the package into the local repository, for use as a dependency in other projects locally
- deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.
Thus, instead of thinking about compiling your source files with <javac>, constructing a JAR with <jar> for your source code, building a WAR file with <war>, including your dependencies, as you do with Ant, you instead thing about packaging your application and, because your POM file tells Maven that your application is WAR file, it knows that it needs to compile your source, build JAR files, find your dependencies, and assemble your WAR file. Finally, it has hooks in place to execute unit tests and integration tests if you have them written.
The only big complaint that I have heard about Maven is that it does not allow you the freedom to do things the way that you want to do them, or rather it makes it more difficult to do things the way you want to do them. For example, if you want to store your Java source files in the following subdirectory in your projects:
src/main/java
It is very easy to use Maven. But if, for some reason you do not like “main” (and there is a “test” which is why there is a “main” and there is a “webapp” which is why there is a “java”) then you have to jump through hoops to make Maven work in your environment. My personal opinion is that the dependency management and the lifecycle abstraction that Maven provides far outweighs any personal preference I may have for the placement of my source files. And, as a friend of mine, Daniel, probably stated far more articulately than I shall do here: if you embrace the system it can make your project management much easier – if you fight it you can eventually make it do what you want, but use th tool for what it is good for.
