Welcome!

Eclipse Authors: Pat Romanski, Elizabeth White, Liz McMillan, David H Deans, JP Morgenthal

Related Topics: Java IoT

Java IoT: Article

An Introduction to Maven - Part II

How to use Maven in product development

In part one of this article we discussed the core competencies of Maven and how it fits into application development and build management. Now we'll delve into some of the practicalities in exercising Maven using a practical example that will walk you through some of the common tasks encountered in typical project development and how they can be done using Maven.

Downloading & Installing Maven
The latest version of Maven 2 can be downloaded at http://maven.apache.org/download.html, Maven's official site. When this article was written, Maven 2.0.6 was the latest version available. It can be downloaded and installed following these steps:

1.  Download the appropriate binary file
2.  Unarchive the binary file and install it in a local directory
3.  Add a maven2InstallationDirectory/bin directory to the system PATH variable
4.  By default, Maven 2 uses ~/.m2/repository as its local repository directory. In case the local repository should point to some other directory, edit maven2InstallationDirectory/conf/settings.xml, uncomment the <localRepository> element and set its value to point to the path location of the new repository directory. For example, <localRepository>/home/mavenuser/m2_repository<local-Repository>
5.  Run the command mvn -help at a command prompt to verify that the installation was successful. Information as shown in Figure 1 should be displayed.

Installing the Maven 2 Plug-in for Eclipse IDE
We'll use Eclipse to demonstrate the example application. The first thing to do would be to install the Maven 2 plug-in for Eclipse so that Maven tasks can be done from inside Eclipse. The benefits of using this plug-in are, as listed on the plug-in's official site (http://m2eclipse.codehaus.org/):

  • Launching Maven builds from within Eclipse
  • Dependency management for the Eclipse build path is based on Maven's pom.xml
  • Resolving Maven dependencies from the Eclipse workspace without installing to a local Maven repository
  • Automatically downloading the required dependencies from the remote Maven repositories
  • Wizards for creating new Maven projects, pom.xml, or enabling Maven support on plain Java project
  • Quick search for dependencies in Maven remote repositories
  • Quick fixes in the Java editor for looking up required dependencies/jars by the class or package name
The following steps will walk you through the installation process:

1)  On the Eclipse file menu, click on Help > Software Updates > Find and Install as shown in Figure 2.
2)  The install and update window will open. Select the option Select for new features to install as shown in Figure 3. Click on the Next button.
3)  The update sites window will be opened as shown in Figure 4. Click on the New Remote Site button.
4)  The new update site dialog window will be opened as shown in Figure 5 and Figure 6. Enter Maven-Eclipse Plugin in the name textbox and http://m2eclipse.codehaus.org/update/ in the URL textbox. Click OK on the New Update Site dialog window. This will add the new site to the list of sites in the Update sites window. Click the Finish button.
5)  The search results window with the Maven Plugin Installation option will be opened as shown in Figure 7. Select the plug-in option and click Next.
6)  The Maven 2 plug-in license agreement window will open. Review and accept it and click the Next button (see Figure 8).
7)  The installation verification window will be opened as shown in Figure 9. Click the Finish button.
8)  The Eclipse download manager will start downloading and installing the Maven 2 plug-in from the specified site. Once the installation is complete, it will prompt you to restart Eclipse. The installation of the Maven 2 plug-in for Eclipse will complete and Maven will be ready to be used after restarting.

Hands-on Example
In this article we'll make an attempt to provide an example that will walk you through some of the common build tasks encountered in typical project development and how they can be executed using Maven.

Most J2EE developers might have been involved in creating and deploying J2EE deployable units such as JARs, WARs, RARs, and EARs. In our example, we considered a J2EE scenario that contains a simple Web application that gets and displays employee details using employee ID. Even though the use case is fairly simple, to illustrate a few of the cornucopia of features available in Maven, we added some complexity by including other components such as EJB, RAR, and an XSD-bound data model that are typically encountered in most J2EE-based applications. The sample application, known as "EmployeeInfo," consists of the following modules:

• The xmlbinding module contains an XSD schema that is used to generate XML-bound Java classes using Castor. This is another concept that had been widely used in Java projects lately that we thought would be useful to illustrate. This module generates a JAR artifact containing XML-bound Java classes.
• The connector module contains a JCA adapter that fetches employee details. This module generates a RAR artifact and uses XML objects interally to represent employee information. Of course, it returns hard-coded values for the details, since the purpose of this example is to illustrate Maven's use in different developmental scenarios.
• The ejb module contains a GetEmployeeDetailsEJB stateless session bean. This module generates a EJB JAR artifact and internally invokes a JCA connector to retrieve an employee info XML object.
• The web contains the JSPs that take in the employee ID user input and displays employee details by calling a stateless session EJB. This module generates a War artifact containing the web application.
• The ear module constitutes the enterprise application that contains the Web application, enterprise java beans, connector, and other dependencies as needed.

In this installment of the article, we will explain how to set up the top level project directory, the 'xmlBinding' module directory structure and how to execute Ant tasks during Maven build process. The rest of the module details along with examples of typical developmental tasks that can be easily accomplished using Maven will be elaborated in the final installment of the article to be published in the next issue of JDJ.

Using Maven Archetypes To Create a Top-Level Project Directory
Archetype is a project templating toolkit. There are built-in Archetypes in Maven that will let developers quickly create a standard project directory layout based on project type. For example, there are Archetypes to create WAR projects and Maven plug-in projects. Table 1 shows some common Archetypes used with Maven. There's a comprehensive list of Archetypes at http://docs.codehaus.org/display/MAVENUSER/Archetypes+List.

Archetype by itself is a Maven plug-in component with typical Maven artifact coordinates. Unlike regular Maven plug-ins that run during Maven build lifecycle phases, An Archetype plug-in gets executed when a Maven project is created. Using Maven Archetypes in creating a project directory structure inculcates consistency in the way project directories are laid out and saves time deciding what the project structure should be.


More Stories By Murali Kashaboina

Murali Kashaboina leads Enterprise Architecture at United Airlines, Inc. He has 15+ years of enterprise software development experience utilizing a broad range of technologies, including JEE, CORBA, Tuxedo, and Web services. Murali previously published articles in WLDJ and SilverStream Developer Center. He has master’s degree in mechanical engineering from the University of Dayton, Ohio.

More Stories By Geeth Narayanan

Geeth Narayanan is a senior architect at Ecommerce Technology, United Airlines, Inc. He has 10 years of experience in the IT industry, specializing in solutions using Java EE technologies. Geeth has master's degree in electrical engineering from the University of Toledo, Ohio.

Comments (2) View Comments

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


Most Recent Comments
Brad 10/05/07 04:58:49 PM EDT

On page 2 the Figure 11 cuts off the command that is used.

I think the command is supposed to be "mvn eclipse:eclipse" to generate Eclipse descriptor.

Nazir Khan 09/27/07 05:37:33 AM EDT

This is an amazing intro to maven 2, it has been very beautifully crafted, which starts telling about the internals of maven and how it works on different scenarios and then taking to practicalities of it. Hats off to the guys who made this wonderful work.

@ThingsExpo Stories
SYS-CON Events announced today that Keisoku Research Consultant Co. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Keisoku Research Consultant, Co. offers research and consulting in a wide range of civil engineering-related fields from information construction to preservation of cultural properties. For more information, vi...
SYS-CON Events announced today that Interface Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Interface Corporation is a company developing, manufacturing and marketing high quality and wide variety of industrial computers and interface modules such as PCIs and PCI express. For more information, visit http://www.i...
SYS-CON Events announced today that MIRAI Inc. will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. MIRAI Inc. are IT consultants from the public sector whose mission is to solve social issues by technology and innovation and to create a meaningful future for people.
SYS-CON Events announced today that Fusic will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Fusic Co. provides mocks as virtual IoT devices. You can customize mocks, and get any amount of data at any time in your test. For more information, visit https://fusic.co.jp/english/.
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
SYS-CON Events announced today that Taica will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Taica manufacturers Alpha-GEL brand silicone components and materials, which maintain outstanding performance over a wide temperature range -40C to +200C. For more information, visit http://www.taica.co.jp/english/.
Join IBM November 1 at 21st Cloud Expo at the Santa Clara Convention Center in Santa Clara, CA, and learn how IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Cognitive analysis impacts today’s systems with unparalleled ability that were previously available only to manned, back-end operations. Thanks to cloud processing, IBM Watson can bring cognitive services and AI to intelligent, unmanned systems. Imagine a robot vacuum that becomes your personal assistant th...
In his session at @ThingsExpo, Greg Gorman is the Director, IoT Developer Ecosystem, Watson IoT, will provide a short tutorial on Node-RED, a Node.js-based programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using a wide range of nodes in the palette that can be deployed to its runtime in a single-click. There is a large library of contributed nodes that help so...
SYS-CON Events announced today that Daiya Industry will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Daiya Industry specializes in orthotic support systems and assistive devices with pneumatic artificial muscles in order to contribute to an extended healthy life expectancy. For more information, please visit https://www.daiyak...
What is the best strategy for selecting the right offshore company for your business? In his session at 21st Cloud Expo, Alan Winters, U.S. Head of Business Development at MobiDev, will discuss the things to look for - positive and negative - in evaluating your options. He will also discuss how to maximize productivity with your offshore developers. Before you start your search, clearly understand your business needs and how that impacts software choices.
SYS-CON Events announced today that SIGMA Corporation will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. uLaser flow inspection device from the Japanese top share to Global Standard! Then, make the best use of data to flip to next page. For more information, visit http://www.sigma-k.co.jp/en/.
SYS-CON Events announced today that Yuasa System will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Yuasa System is introducing a multi-purpose endurance testing system for flexible displays, OLED devices, flexible substrates, flat cables, and films in smartphones, wearables, automobiles, and healthcare.
SYS-CON Events announced today that B2Cloud will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. B2Cloud specializes in IoT devices for preventive and predictive maintenance in any kind of equipment retrieving data like Energy consumption, working time, temperature, humidity, pressure, etc.
SYS-CON Events announced today that NetApp has been named “Bronze Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. NetApp is the data authority for hybrid cloud. NetApp provides a full range of hybrid cloud data services that simplify management of applications and data across cloud and on-premises environments to accelerate digital transformation. Together with their partners, NetApp em...
SYS-CON Events announced today that Ryobi Systems will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Ryobi Systems Co., Ltd., as an information service company, specialized in business support for local governments and medical industry. We are challenging to achive the precision farming with AI. For more information, visit http:...
SYS-CON Events announced today that mruby Forum will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. mruby is the lightweight implementation of the Ruby language. We introduce mruby and the mruby IoT framework that enhances development productivity. For more information, visit http://forum.mruby.org/.
SYS-CON Events announced today that Mobile Create USA will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Mobile Create USA Inc. is an MVNO-based business model that uses portable communication devices and cellular-based infrastructure in the development, sales, operation and mobile communications systems incorporating GPS capabi...
SYS-CON Events announced today that Enroute Lab will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Enroute Lab is an industrial design, research and development company of unmanned robotic vehicle system. For more information, please visit http://elab.co.jp/.
Real IoT production deployments running at scale are collecting sensor data from hundreds / thousands / millions of devices. The goal is to take business-critical actions on the real-time data and find insights from stored datasets. In his session at @ThingsExpo, John Walicki, Watson IoT Developer Advocate at IBM Cloud, will provide a fast-paced developer journey that follows the IoT sensor data from generation, to edge gateway, to edge analytics, to encryption, to the IBM Bluemix cloud, to Wa...
SYS-CON Events announced today that Nihon Micron will exhibit at the Japan External Trade Organization (JETRO) Pavilion at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nihon Micron Co., Ltd. strives for technological innovation to establish high-density, high-precision processing technology for providing printed circuit board and metal mount RFID tags used for communication devices. For more inf...