ONJava.com -- Maven 2.0: Compile, Test, Run, Deploy, and More
来源：百度文库 编辑：16楼社区 时间：2021/05/15 00:46:08
Sign In/My Account |View Cart
MySQL Users Conference April 24-27, 2006, Santa Clara, CA
Register Your Books
Sponsored Developer Resources
ASP.NET 2.0 Training Center
Altova Developer Zone
What are those funny green links?
Java 2EE (Enterprise)
Java 2SE (Standard)
Java and XML
Java Data Objects
Java IDE Tools
JSP and Servlets
Open Source Java
Java API Map
Search and Read Mac Development Books Online
New ADC Article: Using the Accelerate Framework
New ADC Article: Scoping Your Transition Projects
Bookmark with del.icio.us
Maven 2.0: Compile, Test, Run, Deploy, and More
The hardest part of getting started with aJava application is, well, getting started. So many logistical decisions have to be made up front. Where should the Java source files go? Where do I place unit testing? Where will we store dependency .jars? How will the project be built, documented, tested, and deployed? The choices made at this stage will follow a developer for the rest of the project. It‘s up to you whether those choices will haunt you or prove you to be a master Java architect later on. We‘ll assume the latter is the goal we are striving for, and now we just need a starting point.
There are many tools out there for building a Java project, includingAnt. Ant has been on the top of many adeveloper‘s list as the revolutionary tool that got them out of the world of make. For those of you not familiar with make, it‘ll be enough t say that it just isn‘t the best tool to use for building Java projects, since it isn‘t platform-independent and it isn‘t that easy to use. Ant came along and changed all that by providing a platform-independent tool that uses an XML configuration file, the infamous build.xml. Ant has enjoyed heavy popularity with its many advantages, but it also has some drawbacks. The build.xml files can be extremely terse, and their use requires the developer to learn the syntax up front. While the learning curve isn‘t too steep, a Java developer‘s time could be better spent doing, well, development.
Maven is the new kid on the block, much like Ant was just a few short years ago. Maven 1.0 has been around for a few years and it was accepted by a wide audience of developers as an Ant replacement, but it offered very little relief from the old Ant build.xml file. Maven 1.0 was slow and clunky and using it was almost as difficult as getting started on a project with Ant. In fact, it was Ant at its core, and after an almost complete rewrite, Maven 2.0 was born.
The Benefits of Maven 2.0
The benefits of Maven 2.0 are numerous, as it does more than merely build your projects. If you are just starting a new Java project and you need to get started fast, Maven 2.0 will have you up an running in minutes. The following are some of the advantages of Maven 2.0:
Standardized project layout and project structure generator. Standardized dependency-management mechanism. Multiple project support. Instant downloads of new plugins and features as the developer needs them. Website generation for up-to-date project information. Integration with source control: CVS and Subversion.
The list above is just a short list of the features available in Maven 2.0. These alone make Maven 2.0 a solid choice for a build management system. Now that we know what Maven is, let‘s look at how to get started.
The first thing we want to do is set up our directory structure. Wait--there is no need to do it by hand. Maven can do it for you, depending on the type of project that you are developing. Once you have downloaded and extracted the latest distribution ofMaven 2.0, you should add the bin directory of the Maven distribution to your system path. You can run mvn -version to test your installation.
Now that we have the tool installed, let‘s look at the example of creating a simple Java project. Maven usesarchetypes to determine how the directory structure will be laid out. There are several built-in archetypes or you can write one of your own.
mvn archetype:create -DgroupId=com.oreilly -DartifactId=my-app
Voila! We now have our project layout.
my-app ----src ----main - ----java - ----com - ----oreilly ----test ----java ----com ----oreilly
Yes, it‘s that easy. It should be noted that this directory structure can be overridden by creating a new archetype, but deviating from the structure is not recommended, since one of the benefits of Maven is the standard directory structure. The directory structure contains two source trees: one for your Java application source code and one for your unit test code. You may also have noticed that the first time you ran Maven, it did some downloading. Maven will update itself with the appropriate functionality based on what plugin you use when you invoke the tool. Maven, by default, will get its updates from theIbiblio repository. You can override Maven‘s choice of a remote repository in the conf directory of the Maven distribution or in the project itself.
You should also have noticed that Maven created a pom.xml file in the my-app directory. This is the meat and potatoes of your project. The pom.xml file is a set of instructions for Maven that tells it how to build the project and includes other special instructions. (POM is an acronym for "project object model.") By default, Maven also includes the JUnit dependency to encourageunit testing.
Maven: A Developer‘s Notebook
ByVincentÂ Massol,Timothy M.Â O‘Brien
Table of Contents
Search this book on Safari:
Only This Book All of Safari
Code Fragments only
Getting Started with Maven
In this excerpt fromMaven: A Developer‘s Notebook, authors Vincent Massol and Timothy M. O‘Brien show you how to install and start working with Maven, the do-it-all Java project builder/manager.
Maven Project Reporting and Publishing, Part 2
Maven helps you not only with building and tracking your project, but also with releasing it. In this second excerpt fromMaven: A Developer‘s Notebook, authors Vincent Massol and Timothy M. O‘Brien show how Maven can publish artifacts like JAR/WAR/EAR files, automate announcements, generate changelogs, and publish a project website.
Maven Project Reporting and Publishing, Part 1
Maven‘s not just about building; it‘s about viewing, understanding, and managing your projects. In this first part of a two-part excerpt fromMaven: A Developer‘s Notebook, authors Vincent Massol and Timothy M. O‘Brien introduce Maven‘s reporting features for issue tracking, dependencies, code style, and more.
ASP.NET, JSP, PHP and ColdFusion Integration
Learn how to use the most popular Web development technologies together to build rich web applications. This series of more than 40 FREE webcasts will teach you how.
Attend 3 webinars and receive Microsoft Visual Studio 2005 Standard Ed.(NFR) free!
Sign-up for the webcast series today!
Copyright © 2000-2006 O‘Reilly Media, Inc. All Rights Reserved.
All trademarks and registered trademarks appearing on the O‘Reilly Network are the property of their respective owners.
For problems or assistance with this site, email@example.com
ONJava.com -- Maven 2.0: Compile, Test, Run, Deploy, and More ONJava.com -- Clustering and Load Balancing 2 ONJava.com -- Clustering and Load Balancing 2.1 3G: Definition and Much More From Answers.com wikipedia | Christmas: Definition and Much More From Answers.com netizen: Definition and Much More From Answers.com European Union: Definition and Much More from Answers.com amino acid: Definition and Much More from Answers.com acetylcholine: Definition and Much More from Answers.com titanium dioxide: Definition and Much More from Answers.com hypnotism: Definition and Much More from Answers.com decaffeination: Information and Much More from Answers.com indigo: Information and Much More from Answers.com snow cannon: Information and Much More from Answers.com liquid-crystal display: Definition and Much More from Answers.com LED: Definition and Much More from Answers.com Chicken: Definition and Much More from Answers.com bullying: Information and Much More from Answers.com ONJava.com: Ruby the Rival ONJava.com -- What Is Java The Social Net Catches More and More déjà vu: Definition and Much More from Answers.com BVRDE - Remote Compile and Debug IDE Blogs, Blogs and More Blogs