Wednesday, February 4, 2015

Integrate your jdeveloper with FindBug Utility

FindBugs is an useful open source program which looks for bugs in Java code.It uses static analysis to identify hundreds of different potential types of errors in Java programs.Reports from find bug comes very handy when trying to sanitize your application code before moving to a production like environment. I took the help from link to use it as tool within my local jdeveloper. I will explain the same as step by step integration.

1. Download find bug zip from mentioned link, unzip it and place it in your local
2. Write the following xml file to use as ant build file  later

<?xml version="1.0" encoding="windows-1252" ?>
<project xmlns="antlib:org.apache.tools.ant" default="init">
<taskdef name="findbugs" classname="edu.umd.cs.findbugs.anttask.FindBugsTask"/>
  <target name="init">
    <tstamp/>
  </target>
  <property name="findbugs.home" value="C:/HPP/findbugs-3.0.0/findbugs-3.0.0" />
  <target name="findbugs">
    <findbugs home="${findbugs.home}" output="text">    
      <sourcePath path="${basedir}/src/java" />
      <class location="${basedir}/classes" />
    </findbugs>
  </target>

</project>

for this example saving the file as findbug.xml 

3. Now lets start with creating an external tool in jdeveloper. Go to Jdeveloper -- > Tool -- >External tool --> New
4. Select Apache Ant as Tool Type

5. Select the findbug.xml saved in step to as Ant buildfile

6. select findbugs as available target 

7. As mentioned in the build file, it expects a parameter named basedir which has to be added as project directory in this case


8 go with default options for options and process step


9. Make sure you point to findbug-ant.jar(available as<findbug_home/lib/findbug-ant.jar>) as class path entry


10. I am selecting it as Tool Menu in this case and making the availability as always


11. Select your project (either model or view, one at a time) and select FindBug from one of the option in Tool menu to generate the report


Please comment in case of any issues

Edit #1 : Findbugs 3.0 will work only with JDK 1.7. Choose the same in step 8