You are on page 1of 11

Tutorial: Checkstyle for Eclipse

Pre-requisite: Eclipse 3.x

Steps to Setup and use Checkstyle for Eclipse


1. Open the Eclipse and Navigate to Help | Software Updates | ind and !nstall

2. Select the 2nd radio button - Search for new features to install"

3. Click on Ne !e"ote Site# -- add Checkst$le in Na"e# %ield and point it to http&''eclipse-cs.source%orge.net'update

(. )ollo

the

i*ard and hit ne+t# a%ter checking the bo+.

Click on the )inish# button, it

ill start do nloading the chackst$le# -ar %ile.

.%ter do nload, Eclipse per%or"s veri%ication on the do nloaded #ar file. !t takes few $inutes to co$plete. %isplays the &erification details and asks for !nstall'Cancel. Click on the (!nstall" )utton* to install the (chackstyle" plu+in.

/. Create a ne 0ro-ect O! use an$ e+isting pro-ect 1. 2uild the pro-ect 7. 3n the 0ackage e+plorer right-click on 4pro,ect-na$e5# and select Properties | Checkstyle | Check code with Checkstyle Note& 6his ill run the Checkst$le %or this pro-ect Checks 8Eclipse9 - 8:lobal9; ith the de%ault ruleset 7Sun

<. Navigate to -indow | Show &iew | .ther/ 3n the dialog indo , Select Checkstyle | Checkstyle &iolations =. 3n the Checkst$le violations vie , click on the chart icon in the upper right corner. 6his ill open the pie chart vie o% the violations.

Usin+ the Custo$ Checkstyle confi+uration file:


Pre-requisite: Copy the (0yCheckstyle.x$l" to your local $achine in the path: 1eclipse2ho$e13plu+ins3co$.atlassw.tools.eclipse.checkstyle24.3.53 1. Navigate to -indow | Preferences Click on Ne #

2. 0rovide an$ appropriate na"e in the Na"e# %ield and Select E+ternal Con%iguration )ile# as 6$pe %ro" the drop do n list. Click on 2ro se# and Select the appropriate con%iguration >?@ %ile. Click on Open# to return back to previous indo

3. One ne entr$ is created %or the E+ternal Con%iguration )ile#. Click Ok# on the 0re%erences# indo . 3t ill save the settings and close the indo .

(. 3n the 0ackage e+plorer right-click on 4pro-ect-na"e5# and select 0roperties#. 3t ill open the 0roperties# dialog indo .

/. On the 0roperties indo 8above9, select the appropriate na"e 8na"e provided in step 39 %ro" the drop-do n list and click on Ok#.

1. Click on Aes# to !ebuild the pro-ect ith the selected Checkstl$e con%iguration and violations ill be sho n in the Bie .

0odifyin+ the default (6ule Set" confi+uration


7ote: 8his is applica)le to the particular instance of Eclipse

1. Navigate to Window | Preferences | Checkstyle and Click on Ne C 2. Select !nternal Confi+uration, enter a na"e and description. Click !$port/ and

navigate to EC9!PSE2H.0E'plu+ins'co$.atlassw.tools.eclipse.checkstyle2x.x.x and select an$ o% the e+isting rules >?@ %ile 8%or e.g. 0yCheckstyle.x$l:. 6his ill i"port all Sun Eclipse rules %or the ne custo" ruleset. .lso note that Checkst$le ill create a ne custo" ruleset +"l %ile under -.6;SP<CE'.$etadata'.plu+ins'co$.atlassw.tools.eclipse.checkstyle'internal2 confi+22xxxxxxxxxxx.x$l. Click .;. 3. Double click the ne ruleset. 3t opens a dialog indo . Do the reEuired "odi%ication and .ppl$. (. Click .;. 3t ill rebuild the pro-ect and violations ill be sho n in the Bie .

You might also like