developer.com
Search EarthWeb
CodeGuru | Gamelan | Jars | Wireless | Discussions
Navigate developer.com
Architecture & Design  
Database  
Java
Languages & Tools
Microsoft & .NET
Open Source  
Project Management  
Security  
Techniques  
Voice  
Web Services  
Wireless/Mobile
XML  
Technology Jobs  

   Developer.com Webcasts:
  The Impact of Coding Standards and Code Reviews

  Project Management for the Developer

  Defining Your Own Software Development Methodology

  more Webcasts...




See the Winners!


Developer Jobs

Be a Commerce Partner
Cell Phones
Laptop Batteries
Data Center Solutions
Find Software
Calling Cards
Memory
Compare Prices
Promotional Pens
Promotional Golf
KVM Switch over IP
Web Hosting Directory
Corporate Gifts
Promos and Premiums
Corporate Awards

 
Biz Resources
Technology Asset Management Software
Information Technology Services
ecommerce solutions


Developer News -
SaaS Tool Offers Custom Database Development    May 9, 2008
Microsoft’s Automated Agent: Can We Talk?    May 7, 2008
Borland Finally Sells CodeGear    May 7, 2008
Red Hat Heads For The JON 2.0    May 7, 2008
Free Tech Newsletter -

Best Practices for Developing a Web Site: Checklists, Tips, Strategies & More. Download Exclusive eBook Now.

Using Maven for Large Projects
By Michael Nash

Go to page: 1  2  Next  

Having just recovered from the "culture-shock" from converting from Ant to Maven, I'd like to pass on a few words about the experience.

At first glance, Maven seems quite complicated. Rather than writing your own targets, Maven has dozens of its own, already written for you. Then comes the realization that all of the stuff you normally write in Ant scripts is there already; for many projects, you don't need to write a thing.

Where It's At

What you do need to do is follow a specific pattern as to where you put what. Source should go in "src/java", for example. Output jars go in "target", and so forth. These directories can be overridden if you need to, but it's not very difficult to simply adapt to the Maven structure, and it makes for a good standard accross Maven projects.

One special type of location for Maven are "repositories." There are "local" repositories, where Maven maintains versioned copies of all jar files required by your projects, and remote (possibly public) repositories, where versions of jar files reside ready for use in projects.

The Maven project definition (Project Object Model file, or POM) tells Maven what jar file dependencies are required for the specified project, and it will search a list of remote repositories (usually including http://www.ibiblio.org/maven) for the necessary jar files, and download them to the local repository (once) when required. This information is normally stored in project.xml.

All for One

The other concept that makes a lot of sense, once you get used to it, is "one project, one artifact." Simply put, this means that any one Maven project produces a single "artifact," or result file. This is usually a war file (for Web applications) or a jar file, either executable or not. Back when I was using Ant, I've found myself creating a couple of different targets that built different parts of an application—say, one to create the dependency jar files, and another to produce the finished webapp.

The Lingo

The terminology for Maven is not much different from Ant. Instead of "targets," Maven talks about "goals." Each collection of source files designed to produce a certain resulting file (artifact) is a "project," just like Ant. When you see the scripting in Maven (if you ever do), it's a lot like Ant; in fact, virtually every Ant task can be used within Maven scripts, with minor, if any, changes.

Chances are good, however, that you'll not need to write as much custom scripting for Maven as you did with Ant. You'll want to browse the list of available plugins on the Maven site (http://maven.apache.org) to get familiar with what's out there.

Plug It In

Maven is oriented around the concept of a plugin, which, in short, allows you to add custom goals to Maven. A large collection of existing plugins has every goal that most projects need, meaning you have exactly no work to do—other than a bit of learning, that is. For the occasion where you do need to do some custom work, you can create a maven.xml file that is specific to one project, just like a build.xml file for Ant. For larger projects, however, you'll likely want to re-use your custom goals, and creating your own plugin is the answer for this. A plugin is a Maven project just like any other, although it may not have any Java code associated with it if all you need are custom goals without any code. Once a plugin is created, you can "deploy" it to a repository, and the rest of your team can type a single command to download and install it on their local machine.

Plugins, just like every other component Maven handles, are versioned, so you can release updates to your plugin in an organized and controller manner.

Versions, Versions Everywhere

Maven is organized around the concept of versions, for plugins, projects, and dependencies. If you establish a reasonable version numbering mechanism, after a while you'll wonder how you ever got along without Maven.

For example, your primary project might start with a version 1.0, let's say. It, in turn, depends on service-database-1.0.jar. You simply declare this dependency in the project.xml, and Maven takes care of making sure that service-database-1.0.jar is in the classpath when you build your project. If it's not already in the local repository, it searches all known remote repositories to try to find it, and downloads it automatically.

Later, you find a bug in service-database-1.0, and service-database-1.0.1 comes into being. Again, when your project is ready, you simply edit project.xml, increment the version of your main project to (say) 1.1, and build. Now, both 1.0 of the project and 1.1 are able to be built—so in the (unlikely!) event you, ahem, introduced an unintentional feature (a bug) in 1.0.1 of service-database, rolling back is very easy as well. Another month passes and an API change is made to service-database-1.0.1, making it now service-database-2.0. Your existing projects, all of which rely on service-database-1.0.1, with its older API, still work just fine. As they are upgraded to the new API, then simply declare the new dependecy on 2.0. No upheavals, no whipping the rug out from under existing projects when something changes.

Take a SNAPSHOT

In a team development situation, however, sometimes things move a bit faster than the above scenario can easily handle. If bug fixes and enhancements are coming thick and fast, you may want a way to say "this project depends on the very latest available service-database, whatever that is." This is a good spot to use a SNAPSHOT. When creating a jar file for our service-database, we have the option to build and deploy either a versioned jar (for example, 2.0), or a SNAPSHOT. Snapshot is a special version that indicates a current development copy. Unlike regular versions, Maven will check for a new SNAPSHOT version in a remote repository for every build. For "normal" versions, once Maven has downloaded 2.0 (for example), it never tries to get a "new" 2.0. Once 2.0, always 2.0—to get changes, you'd need to go to 2.0.1 (or some other version). With a SNAPSHOT version, though, Maven will automatically fetch the latest SNAPSHOT every time you build your project. For rapidly moving code, this can be a necessity, particularly in a team environment.

Testing, Testing

Maven supports unit, integration, and functional tests. For unit tests, the default is JUnit, making the popular test framework trivial to put to use. Tests are kept (again, by default) in a seperate source tree, and need not be included with your deployed code (or jar).

Maven's default setup is to actually refuse to build the project artifact (jar or war) if all available unit tests are not running successfully. You can override this behavior easily, of course, but it's a good safety for production code.

Enough has been said about the absolute requirement for good testing that I won't repeat the sermon here, other than to say that Maven provides the ideal backbone and structure for a comprehensive test suite at every level.

Go to page: 1  2  Next  


Tools:
Add www.developer.com to your favorites
Add www.developer.com to your browser search box
IE 7 | Firefox 2.0 | Firefox 1.5.x
Receive news via our XML/RSS feed


Languages & Tools Archives

Work With InterSystems. Not Separate Systems. Rapidly develop and deploy connectable applications.
Best Practices for Developing a Web Site. Checklists, Tips & Strategies. Download Exclusive eBook Now.
Data Sheet: IBM Information Server Blade
Flash Demo: Learn how IBM Information Server Blade is easy to manage, highly scalable and efficient.
Developing Intelligent Communications? Visit the Avaya DevConnect Center on DevX.



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