| By Murali Kashaboina, Geeth Narayanan | Article Rating: |
|
| September 1, 2007 05:00 AM EDT | Reads: |
25,660 |
In the parts 1 and 2 of this article, we demonstrated how to download and install Maven 2, how to install the Maven 2 plugin for Eclipse, and how to go about setting up a project directory structure using Maven 2. We used a simple use case for displaying employee details on the Web given an employee ID, but deliberately made the design a bit complex by introducing design concepts such as XML binding, EJBs, and JCA connectors to illustrate a few of the many features offered by Maven. In this final installment of the article, we continue with the remaining modules in our example and illustrate a few more developmental tasks that can be accomplished fairly easily using Maven that otherwise would demand significant time and effort to accomplish.
As described earlier, the 'connector' module yields a RAR artifact containing a JCA connector that uses 'xmlBinding' classes to return Employee information. This means that the 'connector' module will have a dependency on the 'xmlBinding' artifact and any artifact that can provide JCA classes. We'll use Maven's 'Add Dependency' feature in Eclipse to add these dependencies as described below.
1. In the Eclipse 'Package Explorer' pane, right-click on the 'connector' module's POM file and in the menu, select 'Add Dependency' Maven2 option as shown in Figure 1.
2. A dialog window to search for artifacts in the Maven repository will be displayed. In the search box, type 'com.somecompany.' The search results will be displayed in the text area as shown in Figure 2.
3. Expand the 'com.somecompany xmlBinding' result entry, select the 'xmlBinding-1.0.jar' option, and click the 'OK' button. The dependency on the 'xmlBinding' artifact will be added in the POM file.
4. To add JCA specification classes, we'll use a Geronimo JCA specification artifact as a dependency. Following the same approach as described before, search for 'geronimo' in the repository search window and select 'geronimo-spec-j2ee-connector-1.0-M1.jar' as a dependency to be added as shown in Figure 3.
5. The two dependencies will be added to the POM file. The scope element should be added to the 'geronimo-spec-j2ee-connector' dependency element with a value of 'provided' indicating that JCA classes will be provided by the underlying J2EE application server. Below is the modified POM.
<project>
<parent>
<artifactId>EmployeeInfo</artifactId>
<groupId>com.somecompany</groupId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>connector</artifactId>
<packaging>rar</packaging>
<name>connector</name>
<dependencies>
<dependency>
<groupId>com.somecompany</groupId>
<artifactId>xmlBinding</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>geronimo-spec</groupId>
<artifactId>geronimo-spec-j2ee-connector</artifactId>
<version>1.0-M1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
It's time to add connector implementation Java classes. The source files that we developed for the connector are shown in Figure 4.
Download and review the source files to understand the complete implementation. However, the important classes to note are 'EmployeeInfoCCIConnection,' 'EmployeeInfoCCIInteraction,' and 'EmployeeInfoSPIManagedConnection.' The sequence diagram as shown in Figure 5 gives a high-level view of the method calls that a client will invoke to retrieve employee information using an employee ID. For brevity's sake, the sequence diagram is kept simple.
The RAR artifact for the 'connector' module can be created by adding 'maven-rar-plugin.' By default, this plug-in will look for RAR meta-information such as the 'ra.xml' descriptor file under the 'src/main/rar/META-INF' directory. The 'ra.xml' descriptor is in Listing 1.
Static Analysis of Code using Maven
Errors in the code are typically detected via code reviews, unit testing, system testing, integration testing, and user-acceptance testing. Code reviews certainly help in early bug detection by enforcing language-specific programming standards and best practices. However code reviews are carried out manually and hence the process can be cumbersome and inefficient particularly in case of large projects. Static analysis is a tool-based automated code review mechanism typically used to find code defects early in the build phase. Static analysis ensures early bug detection and remediation by comparing source code with predefined language patterns. It also helps in enforcing coding conventions and thereby improves code quality.
PMD is a static analysis tool for Java code. PMD packages a number of ready-to-run rules that can identify unused variables, unnecessary object creation, and empty catch blocks in the source code. Custom rules can also be incorporated. PMD can be executed using Maven by including 'maven-pmd-plugin' in the POM file as shown in the following snippet. The PMD plug-in lets you automatically run the PMD code analysis tool on your project's source code and generate a site report with its results. For more information on the PMD Maven plug-in, refer to plug-in documentation available at http://maven.apache.org/plugins/maven-pmd-plugin/.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
</plugin>
PMD plug-in can be invoked at the command line within the module directory by running the command below. However, with the current implementation, the plug-in will generate reports only in case of 'jar,' 'war,' and 'ejb' POM packaging types. Since the current POM is a 'rar' packaging type, the packaging type should be temporarily changed to 'jar' so that PMD plug-in can generate the reports.
mvn pmd:pmd
When this command is executed after temporarily changing the packaging type to 'jar,' Maven will invoke the PMD plug-in that will run the code analysis and create reports under the 'target/site' directory with the main report in the 'pmd.html' file. Figure 6 is the report generated for the 'connector' module source code. Make sure to reset the packaging type back to 'rar.'
Published September 1, 2007 Reads 25,660
Copyright © 2007 SYS-CON Media, Inc. — All Rights Reserved.
Syndicated stories and blog feeds, all rights reserved by the author.
More Stories By Murali Kashaboina
Murali Kashaboina is a lead architect at Ecommerce Technology, United Airlines, Inc. He has more than 10 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.
![]() |
Aladin SOHAILI 10/06/07 04:38:08 PM EDT | |||
Any link to download source files ? |
||||
![]() |
Bob Arnold 09/11/07 02:34:39 PM EDT | |||
Regarding: "It's time to add connector implementation Java classes. The source files that we developed for the connector are shown in Figure 4. Please specify the download link for the source code referred to. |
||||
![]() |
vinny 09/04/07 08:40:13 AM EDT | |||
Where is the link to download source files for connector EmployeeInfoCCIConnection?? |
||||
![]() |
Magne 09/04/07 03:25:58 AM EDT | |||
It was with great interest I read these articles. -magne |
||||
![]() |
Duty Editor 08/31/07 01:16:44 PM EDT | |||
The Links to Parts I and II are to be found at the foot of the final page. -Duty Editor |
||||
![]() |
Jim 08/31/07 11:51:57 AM EDT | |||
Next time you write part 3 of a three-part series, please include clickable links to the first two parts right there at the top. |
||||
- IBM Puts Systems Chief on Leave of Absence
- Amazon Web Services Database in the Cloud
- SpringSource Moving to Spring 3.0
- Un-Clouding Federal Security Compliance
- United Planet offers practical portal building tips for SMBs
- The Bunker achieves PCI DSS Compliance
- Developing APIs for the Cloud
- Qt DevDays 2009 - Munich
- Canonical Offers Free Cloudware
- New-Generation Virtualization Technologies with Ultra Low-Cost Endpoints
- Microsoft Nudges Eclipse Developers to Windows-Ware
- Trusting the Cloud
- Oracle-Sun: IBM Reportedly Behind Delay
- The Case for Single-Purpose Services
- Current Trends in the Data Management Market
- IBM Puts Systems Chief on Leave of Absence
- Cloud BI & Amazon VPC
- The Curious Case of Build Release Management eBook
- Cloud-Oriented Switch Start-up Valued at $230M
- Tips for Efficient PaaS Application Design
- Reporting Solutions Using Crystal Reports for Eclipse
- Amazon Web Services Database in the Cloud
- SpringSource Moving to Spring 3.0
- Five Ways to Incorporate CMMI with Agile Methods
- Java Developer's Journal Exclusive: 2006 "JDJ Editors' Choice" Awards
- The i-Technology Right Stuff
- Creating Web Applications with the Eclipse Web Tools Project
- Eclipse Special: Remote Debugging Tomcat & JBoss Apps with Eclipse
- The Next Programming Models, RIAs and Composite Applications
- Where Are RIA Technologies Headed in 2008?
- How to Bring Eclipse 3.1, J2SE 5.0, and Tomcat 5.0 Together
- SYS-CON Webcast: Eclipse IDE for Students, Useful Eclipse Tips & Tricks
- Eclipse: The Story of Web Tools Platform 0.7
- "Eclipse 3.0 is a Great Leap Forward," Says JDJ's Dudney
- Developing an Eclipse BIRT Report Item Extension
- Eclipse Special: Bill Dudney Looks at New Stuff in M9



































