advertisement
Premier Club Log In/Registration
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   SKILLBUILDING  |   TIP BANK  |   SOURCEBANK  |   FORUMS  |   NEWSLETTERS
Browse DevX
Sidebar 1. Maven Term and Concept Summary
Sidebar 2. Maven Versus Ant
Sidebar 3. Jelly: Executable XML
How valid is the statement that Maven is a potential replacement for Ant? Which Maven features would make you switch?
Partners & Affiliates
advertisement
advertisement
Average Rating: 4.4/5 | Rate this item | 15 users have rated this item.
 Print Print
 
Apache Maven Simplifies the Java Build Process—Even More Than Ant
Apache Maven's reuse mechanisms simplify the build process and generally improve upon the popular Ant tool's functionality. In fact, developer and Java technology trainer Dave Ford believes Maven could very well replace Ant as your preferred Java build tool. 

advertisement
pache Maven, a potential replacement for the Java-based Apache Ant build tool, promises to eliminate the hassle of maintaining complicated build scripts. This new tool (along with a new approach) can automate the Java build process. Just give Maven a bit of information about your project's directory structure and it handles the rest. All of the functionality required to build your project (clean, compile, copy resources, etc.) is built right into Maven. In other words, for standard builds you don't need to create a custom build script at all.

In this article, I'll explain exactly what Maven is and which problems it attempts to solve. Then, I'll walk you through automating your own build process using Maven. As Ant currently is the most popular build tool in the Java arena, this article also assumes the reader has a basic understanding of it.

The Build Process Automates Daily Tasks
As programmers, we spend most of our time automating tasks for others. But what about automating tasks for ourselves? IDEs automate much of our work, but many developers look to an external tool for one particular task: the build process. The build concept has evolved over the years, and build tools today automate just about any task that a developer may encounter while developing, compiling, testing, or deploying software.

For my work, I am grudgingly using a general-purpose, scripting language more and more with the build tool—not unlike the macro languages built into IDEs. Table 1 shows a few of the build functions that I perform daily.
Table 1. Daily Build Functions I Perform
Compile Run jikes or javac
Copy Copy resource files into the classes directory
Clean Delete the classes directory so that our next compile will be a clean compile
Delete any temporary, app-server-generated files
Recreate the classes directory
Jar Zip up a project in to a .jar file
Javadoc Generate documentation from source code
Test Use JUnit to run the project's unit tests
Deploy Copy runtime files to a staging server
Kodo Run Kodo's JDO byte-code enhancer (Kodo is a JDO implementation that post-processes class files to make them persistence-capable.)

Move Over Ant, Maven Is Here
When I first started using Ant to automate the above-mentioned tasks, it was a big timesaver. Especially once I learned to use and create custom Ant Tasks. But that was for individual, fairly simple projects. I now use Ant to automate build tasks for multiple, complex projects. A considerable part of my day is spent creating and maintaining complex Ant scripts. Over time, maintaining these scripts became a major thorn in my side.

Specifically, the following Ant limitations led me to start looking for a new build tool:

  1. Cross-project reuse. My 10 Ant build scripts are mostly the same. So I started looking for code reuse features in Ant. As it turns out, Ant has no convenient way to reuse targets across projects. Copy-and-paste is the only choice.
  2. Cross-developer reuse. Most of my Ant scripts are complex but not particularly unique to my project. In other words, since most of my build scripts perform the same functions as other people's build scripts, why should I have to create a build script at all—other than for project-specific functionality?
  3. Logic and looping. As mentioned previously, I now use Ant for general-purpose scripting. Therefore, I need general-purpose scripting features, like conditional logic, looping constructs, and reuse mechanisms. Ant was never meant to be a general-purpose scripting tool, however. As such, although possible via the Script Task or a custom Task, adding conditional logic and looping to the Ant build process is awkward.

To be fair, Ant does allow you to create custom Tasks, which are reusable across projects. These are a great help and probably are the reason for Ant's success. However, even with reusable Tasks, you still end up with numerous, mostly redundant Targets in each project. If your objective is to simplify or eliminate the build script, you need something more. You need reusable Target Libraries. That's where Maven comes in.

Maven addresses these issues. With this new tool, targets (which Maven calls goals) are reusable (See the sidebar "Maven Term and Concept Summary" for a complete listing of Maven terminology.). In fact, for the most common tasks, Maven has already created the goals. This means you don't have to create them yourself. For simple projects, you may not need a build file at all. (See the sidebar "Maven Versus Ant" for a comparative analysis of Ant and Maven.)

Maven + POM = Goals Achieved
To achieve its magic, Maven uses a Project Object Model (POM), which describes a project in the form of an XML file, project.xml. Specifically, it describes the project's directory structure, its jar file dependencies, and some of its project management details. Think of the POM as project meta-data. Once you describe your project to Maven by creating the POM, you can invoke any of Maven's built-in goals (remember, a goal is like an Ant target).

The following sections demonstrate Maven. They walk you step by step through creating a simple project and invoking some of the Maven-provided goals.

Install Maven
To install Maven:

  1. Download the latest archive from the Maven Web site and unzip it.
  2. Set the MAVEN_HOME environment variable.
  3. Add <MAVEN_HOME>/bin to your PATH environment variable.

Keep in mind that the first time you use Maven to build a project it will download a bunch of jar files from the Net. These jar files are needed by Maven's plethora of plug-ins (which I describe later). So you may have time to get a cup of coffee while waiting.

Page 1 of 4
advertisement
  Next Page: Create a Simple Maven Project
Page 1: IntroductionPage 3: Integrate Unit Testing
Page 2: Create a Simple Maven ProjectPage 4: Protect Your Resources
advertisement
Advertising Info  |   Member Services  |   Permissions  |   Contact Us  |   Help  |   Feedback  |   Site Map  |   Network Map  |   About


JupiterOnlineMedia

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info


Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Solutions
Whitepapers and eBooks
Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
Avaya Article: How to Feed Data into the Avaya Event Processor
Microsoft Article: Install What You Need with Win Server ‘08
HP eBook: Putting the Green into IT
Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
Avaya Article: Setting Up a SIP A/S Development Environment
IBM Article: How Cool Is Your Data Center?
Microsoft Article: Managing Virtual Machines with Microsoft System Center
HP eBook: Storage Networking , Part 1
Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
MORE WHITEPAPERS, EBOOKS, AND ARTICLES
Webcasts
Intel Video: Are Multi-core Processors Here to Stay?
On-Demand Webcast: Five Virtualization Trends to Watch
HP Video: Page Cost Calculator
Intel Video: APIs for Parallel Programming
HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
MORE WEBCASTS, PODCASTS, AND VIDEOS
Downloads and eKits
Sun Download: Solaris 8 Migration Assistant
Sybase Download: SQL Anywhere Developer Edition
Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
Red Gate Download: SQL Compare Pro 6
Iron Speed Designer Application Generator
MORE DOWNLOADS, EKITS, AND FREE TRIALS
Tutorials and Demos
How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
IBM Article: Collaborating in the High-Performance Workplace
HP Demo: StorageWorks EVA4400
Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
Microsoft How-to Article: Get Going with Silverlight and Windows Live
MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES