How to use PMD with eclipse
Tech-Today

How to use PMD with eclipse


This tutorial will explain how to use PMD (http://pmd.sourceforge.net/) with eclipse.

What you need:
1.) eclipse-java-helios
2.) PMD (download the latest version here: http://pmd.sourceforge.net/). Extract in c:\java
a.) From here you can download a zipped update site, install that in eclipse by:
Help->Install New Software->Add->Archive->Then just follow the steps.
3.) After eclipse update, you can immediately run PMD by: right click project->PMD->Generate reports. You can refer on the pmd link for more explanations.
4.) For example this code that I copied from PMD website:
package com.kbs.testng;


public class TestPMDDemo {
public static void main(String args[]) {
try {
// do something
} catch (Throwable th) { // Should not catch throwable
th.printStackTrace();
}
}
}
Will output:

5.) If you want to run PMD via ant task, here's the script (add this to your build.xml):

<?xml version="1.0" encoding="UTF-8"?>

<project name="JavaHelpers" default="" basedir=".">
<!-- set global properties for this build -->
<property name="program_name" value="JavaHelpers" />
<property name="package_name" value="JavaHelpers" />
<property name="src" value="src" />
<property name="build" value="build" />
<property name="pmd.home" value="C:/java/pmd-4.2.5" />
<property name="pmd.jar" value="pmd-4.2.5.jar" />

<path id="compile.boot.path">
<fileset dir="${testng.home}">
<include name="${testng.jar}" />
</fileset>
<fileset dir="${java.home}/lib">
<include name="rt.jar" />
</fileset>
</path>

<target name="pmd">
<taskdef name="pmd" classname="net.sourceforge.pmd.ant.PMDTask">
<classpath location="${pmd.home}/lib/${pmd.jar}" />
</taskdef>
<pmd shortFilenames="true">
<ruleset>rulesets/favorites.xml</ruleset>
<ruleset>basic</ruleset>
<formatter type="html" toFile="pmd_report.html" linkPrefix="http://pmd.sourceforge.net/xref/" />
<fileset dir="${src}">
<include name="**/*.java" />
</fileset>
</pmd>
</target>

<!-- Compile Source -->
<target name="compile">
<mkdir dir="${build}/classes" />
<javac destdir="build/classes" target="1.6" source="1.6">
<bootclasspath refid="compile.boot.path" />
<src path="${src}" />
<include name="**/*.java" />
</javac>
</target>
</project>
It will create a file: pmd_report.html in the project's root directory.




- How To Package A Java Standalone App Using Maven Assembly
The sample codes below will assemble a zipped package of a java standalone app. Dependencies: maven-jar-plugin - to create the jarmaven-assembly-plugin - to assemble the distribution packagepom.xml<plugin> <groupId>org.apache.maven.plugins</groupId>...

- How To Generate Wadl Via Maven Plugin
So you've written your web service and would now want to create the wadl for it.  Assuming you have your web project in eclipse with maven integrated this is what you have to do: 1.) Add the lines below to your pom, you may want to create it's...

- A Maven Project That Have Multiple Property Files Via Maven Antrun Plugin
This tutorial will answer several questions (below) within a maven project that has several configuration files (dataset, property, persistence). 1.) How to have multiple persistence, datasource and property files depending on the profile or environment...

- How To Add Pmd Reporting To Maven
Before proceeding to this exercise, you may want to try my tutorial on how to setup a maven project to eclipse: http://czetsuya-tech.blogspot.com/2012/04/how-to-create-modularized-maven-project.html. Assuming you have follow the tutorial above, you should...

- Useful Tools When Building A J2ee Project
Below are the tools I commonly use when setting up my eclipse and before creating a new project. JBoss Tools - http://download.jboss.org/jbosstools/updates/nightly/trunk/ TestNG - http://beust.com/eclipse FindBugs - http://findbugs.cs.umd.edu/eclipse/...



Tech-Today








.