Eclipse Part1– Useful Configuration and Settings For Eclipse

Introduction:

The static code analysis tools Code Formatter, Findbugs, PMD and Checkstyle are widely used in the Java development community. Each has an own purpose, strength and weaknesses.

This post explains about eclipse useful and important configuration and setting which required for every developer who used eclipse as primary IDE(Integrated Development Environment) for project development.

 


Configure Java Code Formatter


This post explains about configuring formatter in eclipse which helps developer to keep Java Source code in the same format across all developer.

Java Source code having different format on different system (Developer’s System) once project have many developers and they are using their own formatter or not using any formatter. In order to keep Java File format same we have to configure  same formatter across team. please follow below steps to configure formatter in your eclipse, Also you can download sample formatter for your project from below link –

 

Step 1: Download/Install eclipse if you are not having in your system.

Step 2: Launch eclipse and select appropriate workspace. eclipse Home page will display.

eclipse_home

Step 3: Navigate to Window option from the top menu and click on Window as given below screenshot.

eclipse_window_preferences

Step 4: Navigate to Preferences and click on it.

Step 5: Once Preference Model Window available then Navigate to Java then Code Style and Formatter from the left hand side panel. please find screenshot as given below –

Eclipse_preferences_screen

Edit: Click on Edit to modify already existing code formatter in your workspace.

New: Click on New if you want to create new code formatter from scratch suing eclipse.

Import: Click on Import if you want to import already existing code formatter in your eclipse.

Step 6: Click on import to import already existing code formatter file from system.

eclipse_codeFormatter_import

Step 7: Click on Apply to activate this code formatter in your eclipse.

eclipse_codeFormatter_import2

Step 8: Click on OK to complete configuration.

 

eclipse_codeFormatter_import3

Step 9: Navigate any Java File to view the changes. Just press Ctrl+A and do Ctrl+Shift+F to format code.

Code Before Formatter Used:

codeformatter_before

Code After  Formatter Used:

codeformatter_after

Now code looks good and it will display same across all the system and if anyone change then it will show only those changes.     

Java Code Formatter Link: Click on below to download Java code formatter file.

Java Code Formatter

Java Code Formatter


Configure Check Style


Checkstyle is a development tool to help programmers write Java code that adheres to a coding standard. It automates the process of checking Java code to spare humans of this boring (but important) task. This makes it ideal for projects that want to enforce a coding standard.

Checkstyle is highly configurable and can be made to support almost any coding standard. An example configuration files are supplied supporting the Sun Code Conventions, Google Java Style.

In order to configure and activate check style in your eclipse you need check style plugin installed in your eclipse. You can check check style plugin in your eclipse using window -> preferences option from the top of the menu.

Type checkStyle in the text area and you will find checkStyle option below in the screen. checkStyle already Installed in my eclipse and now project specific CheckStyle can be configure.

eclipse_cs1

 

CheckStyle Plugin installation steps involve installation of plugin on your eclipse so project specific checkStyle can be uploaded.

Please find the steps below –

Step 1: You can install the Checkstyle Eclipse plugin using Eclipse update manager from the following links

http://eclipse-cs.sourceforge.net/update

Step 2: Navigate to Help option from the top menu and click on Install New Software, please find the option in below screenshot

eclipse_cs2 

Step 3: Click on Add button to add above url to download and install plugin in your eclipse. Complete Name and Location information and click on OK button.

eclipse_cs3

Step 4: Once Url added it will start showing CheckStyle package to install in your eclipse as below given screenshot. please click on Next button and complete the installation.

eclipse_cs4

 

Step 5: Above steps helped us to install checkStyle Plugins in eclipse, Now click on Window and then Preferences to configure project specific CheckStyle.

eclipse_cs1

 

Step 6: Click on New button to configure CheckStyle. Check style configuration page will display.

eclipse_cs5

Step 7: Complete CheckStyle Configuration Page as per above screen and Browse CheckStyle file from your system and click on OK button.

eclipse_cs6

Step 8: After Clicking on OK button above screen display and project specific CheckStyle configured in eclipse. We need to click on Set As Default to make this CheckStyle as default.

After Clicking on Set As Default button project specific CheckStyle will be default.

eclipse_cs7

 

Step 9: Click on OK button to complete the configuration. It will show confirmation window, please click on yes.

Step 10: To execute CheckStyle please right click on Java File and Navigate to Checkstyle -> Check Code with checkStyle option.

eclipse_cs8

 

Step 11: Click on Check Code with checkstyle with give you checkstyle report.

 

CheckStyle File Download Link: Click on below to download checkstyle file.

CheckStyle File

 


Findbugs Configuration


FindBugs is an open source project for a static analysis of the Java bytecode to identify potential software bugs. Findbugs provides early feedback about potential errors in the code. This helps the developer to access these problems early in the development phase.

The analysis of Findbugs can be integrated into existing IDEs like the Eclipse IDE of IntelliJ.

The FindBugs Eclipse plugin allows FindBugs to be used within the Eclipse IDE. The FindBugs Eclipse plugin was generously contributed by Peter Friese. Phil Crosby and Andrey Loskutov contributed major improvements to the plugin.

To use the FindBugs Plugin for Eclipse, you need Eclipse 3.3 or later, and JRE/JDK 1.5 or later.

Please follow below steps to Install and execute FindBugs in your eclipse –

Step 1: Use the HelpInstall New Software… menu entry to install all the FindBugs components from the following URL. Restart your Eclipse IDE afterwards.  (As above we did for CheckStyle)

Reference: Help >  Install New Software

Add http://findbugs.cs.umd.edu/eclipse URL and install Plugin.

eclipse_fb1

Step 2: Clicking on Next and Complete the installation. Once FindBugs Plugin Installed in your eclipse then you can verify it using Window -> Preferences menu item from the top of the eclipse. Just Type FindBugs in the text Box then it shows FindBugs option in the search window, please find screenshot below –

eclipse_fb2

User can configure it as per their requirement.

Step 3: We can execute FindBugs by Right Click on the project and using FindBugs otpion, please find screenshot below –

eclipse_fb3

Clicking on Find Bugs option it will start preparing FindBugs Reports for that particular project(Ex. KnowledgeWalaLibrary). It show confirmation page.

eclipse_fb4

Step 4: We  enable FindBugs View using Window -> Show View -> Bug Explorer as below screenhot.

eclipse_fb5

Step 5: Once View enabled on eclipse then it start showing FindBugs Reports, please find screenshot below –

eclipse_fb6

User can download FindBugs Report using option available there and also clean previous run before running next time.

Troubleshooting

This section lists common problems with the plugin and (if known) how to resolve them.

  • If you see OutOfMemory error dialogs after starting FindBugs analysis in Eclipse, please increase JVM available memory: change eclipse.ini and add the lines below to the end of the file:
        -vmargs
        -Xmx1000m

PMD Configuration


PMD is an alternative to FindBugs and it is having good name in the market.

PMD  stands for Programming Mistake Detector. It is a free source code analysis tool which helps you to find the bugs in your java code and improve the code quality. PMD helps to find empty try/catch/finally statements, while/if statements, unnecessary object creation etc.

PMD warning and problems are not exactly errors, but shows that particular code need to be improved

Following plugins are available for PMD

  1. Maven PMD plugin
  2. NetBeans PMD plugin
  3. JBuilder PMD plugin
  4. JDeveloper PMD plugin
  5. IntelliJ PMD plugin

Please follow below steps to install and execute PMD plugin in your eclipse –

Step 1: You can install the PMD Eclipse plugin using Eclipse update manager from the following links

http://sourceforge.net/projects/pmd/files/pmd-eclipse/update-site/

or

http://pmd.sf.net/eclipse

Step 2: Use the HelpInstall New Software… menu entry to install all the PMD plugin components from the above URL.

Step 3: Enter the URL and name and click on OK button.

eclipse_pmd1

Click On Next button.

eclipse_pmd2

Step 4: Once you Click on OK Button then it display all available installation for eclipse, select appropriate eclipse version and click on Next button. Please find the screenshot below –

eclipse_pmd3

Step 5: After Clicking on Next button then it display license agreement . Select the License agreement and Click on Next button.

eclipse_pmd4

Step 6: Click on Finish button and it display below screen.

eclipse_pmd5

Step 7: Once installation completed then it ask to Restart eclipse, Restart your eclipse to validate PMD plugin in your eclipse.

Step 8: User can validate PMD plugin installation using Window -> Preferences option from the top menu.

Enter PMD in text area then it appear on the screen. please use the feature same as FindBugs to execute and generate Reports.

User Can execute PMD by Right Clicking on the project and Create Reports option, please find screenshot in the attachment.

eclipse_pmd6

One thought on “Eclipse Part1– Useful Configuration and Settings For Eclipse”

Leave a Reply

Your email address will not be published. Required fields are marked *