•
•
•
•
•
•
TableofContents
Index
Reviews
ReaderReviews
Errata
Academic
Eclipse
BySteveHolzner
Publisher :O'Reilly
PubDate :April2004
ISBN :0-596-00641-1
Pages :334
Slots :1.0
O'Reilly'snewguidetothetechnology,
Eclipse,providesexactlywhatyou'relooking
for:afast-trackapproachtomasteryof
Eclipse.Thisinsightful,hands-onbook
deliversclearandconcisecoverage,withno
fluff,thatgetsdowntobusinessimmediately.
Thebookistightlyfocused,coveringall
aspectsofEclipse:themenus,preferences,
views,perspectives,editors,teamand
debuggingtechniques,andhowthey'reused
everydaybythousandsofdevelopers.
Developmentofpracticalskillsisemphasized
withdozensofexamplespresented
throughoutthebook.
•
•
•
•
•
•
TableofContents
Index
Reviews
ReaderReviews
Errata
Academic
Eclipse
BySteveHolzner
Publisher :O'Reilly
PubDate :April2004
ISBN :0-596-00641-1
Pages :334
Slots :1.0
Copyright
Preface
What'sInside
ConventionsUsedinThisBook
WhatYou'llNeed
We'dLiketoHearfromYou
UsingCodeExamples
Chapter1.EssentialEclipse
Section1.1.EclipseandJava
Section1.2.GettingEclipse
Section1.3.UnderstandingEclipse
Section1.5.WorkingwithEclipse
Section1.4.ViewsandPerspectives
Section1.6.UsingQuickFix
Section1.7.AWordAboutProjectManagement
Chapter2.JavaDevelopment
Section2.1.DevelopingJavaCode
Section2.2.BuildingandRunningCode
Section2.3.CreatingJavadoc
Section2.5.SomeEssentialSkills
Section2.4.Refactoring
Section2.6.CustomizingtheDevelopmentEnvironment
Chapter3.TestingandDebugging
Section3.1.TestingwithJUnit
Section3.2.Debugging
Chapter4.WorkinginTeams
Section4.1.HowSourceControlWorks
Section4.2.UnderstandingCVS
Section4.3.FindingaCVSServer
Section4.4.AddingaProjecttotheCVSRepository
Chapter5.BuildingEclipseProjectsUsingAnt
Section5.1.WorkingwithAnt
Section5.2.JARingYourOutput
Section5.3.ConfiguringAntinEclipse
Section5.4.CatchingErrorsinBuildFiles
Chapter6.GUIProgramming:FromAppletstoSwing
Section6.1.CreatingAWTApplications
Section6.2.CreatingSwingApplications
Section6.3.UsingEclipsePlug-ins
Section6.4.UsingtheV4ALLPlug-in
Chapter7.SWT:Buttons,Text,Labels,Lists,Layouts,andEvents
Section7.1.JavaGraphics
Section7.2.AnSWTExample
Section7.3.WorkingwithButtons
Section7.5.WorkingwithLists
Section7.4.WorkingwithCompositesandLayouts
Section7.6.UsingV4ALLwithSWT
Chapter8.SWT:Menus,Toolbars,Sliders,Trees,andDialogs
Section8.1.WorkingwithMenus
Section8.2.WorkingwithToolbars
Section8.3.WorkingwithSliders
Section8.5.WorkingwithDialogs
Section8.4.WorkingwithTrees
Section8.6.OpeningInternetExplorerinanSWTWindow
Chapter9.WebDevelopment
Section9.1.InstallingandTestingTomcat
Section9.2.CreatingaJSP
Section9.3.CreatingaServlet
Section9.5.ConnectingtoaJavaBean
Section9.7.DeployingWebApplications
Section9.4.CreatingaServletinPlace
Section9.6.UsingtheSysdeoTomcatPlug-in
Chapter10.DevelopingStrutsApplicationswithEclipse
Section10.1.StrutsandEclipse
Section10.2.CreatingtheView
Section10.3.CreatingtheController
Section10.5.UsingtheEasyStrutsPlug-in
Section10.4.CreatingtheModel
Chapter11.DevelopingaPlug-in:ThePlug-inDevelopmentEnvironment,
Manifests,andExtensionPoints
Section11.1.AllYouReallyNeedIsplugin.xml
Section11.2.UsingthePlug-inDevelopmentEnvironment
Section11.3.UsingtheRun-timeWorkbench
Section11.4.CreatingaStandardPlug-in
Chapter12.DevelopingaPlug-in:CreatingEditorsandViews
Section12.1.CreatingaMulti-PageEditor
Section12.2.CreatingaView
Section12.3.DeployingaPlug-in
Chapter13.Eclipse3.0
Section13.1.ALookatEclipse3.0
Section13.2.CreatingaJavaProject
Section13.3.ChangestotheEclipsePlatform
Section13.5.OtherChanges
Section13.4.ChangestotheJavaDevelopmentTools
Colophon
Index
Copyright©2004O'ReillyMedia,Inc.
PrintedintheUnitedStatesofAmerica.
PublishedbyO'ReillyMedia,Inc.,1005GravensteinHighway
North,Sebastopol,CA95472.
O'Reilly&Associatesbooksmaybepurchasedforeducational,
business,orsalespromotionaluse.Onlineeditionsarealso
availableformosttitles().Formore
information,contactourcorporate/institutionalsales
department:(800)998-9938or
NutshellHandbook,theNutshellHandbooklogo,andthe
O'ReillylogoareregisteredtrademarksofO'ReillyMedia,Inc.
ThetitleofEclipse,theimagesofornatebutterflyfish,and
relatedtradedressaretrademarksofO'ReillyMedia,Inc.
JavaandallJava-basedtrademarksandlogosaretrademarks
orregisteredtrademarksofSunMicrosystems,Inc.,inthe
UnitedStatesandothercountries.O'ReillyMedia,Inc.is
independentofSunMicrosystems,Inc.
Manyofthedesignationsusedbymanufacturersandsellersto
distinguishtheirproductsareclaimedastrademarks.Where
thosedesignationsappearinthisbook,andO'ReillyMedia,Inc.
wasawareofatrademarkclaim,thedesignationshavebeen
printedincapsorinitialcaps.
Whileeveryprecautionhasbeentakeninthepreparationofthis
book,thepublisherandauthorassumenoresponsibilityfor
errorsoromissions,orfordamagesresultingfromtheuseof
theinformationcontainedherein.
Preface
WelcometoEclipse,today'spremiereJava™Integrated
developmentenvironment(IDE).Eclipseisanextraordinary
tool,anditfillsalong-standingneedamongJavadevelopersno
longerdoyouhavetosufferthroughpagesoferrorsscrolling
offthescreenwhileusingcommand-lineJavacompilers.Now
you'vegotanIDEthatwillhandlethedetailsforyou,letting
yougetonwithwritingcode.Ifyou'veneverusedEclipse
before,yourproductivityisabouttotakeagiantjump.
We'regoingtopushtheEclipseenvelopeinthisbook,working
fromthebasicsupthroughtheadvanced.Thisbookhasbeen
designedtoopenupEclipseandtobemoreaccessiblethanany
other.It'saprogrammer-to-programmerbook,writtentobring
youuptospeedinEclipsewithoutwastingtime.
Ifyou'reaprogrammer,thisbookiswrittentogiveyouexactly
whatyouwanttoseethegoodstuff,andonlythegoodstuff.
There'sasmuchEclipsecrammedintothisbookasyouneedto
masterthetopic,andmasteringEclipseisourgoal.
What'sInside
Fromcovertocover,thisbookispureEclipse,covering
hundredsofskillsandtechniques.Westartfromthemostbasic
Javadevelopmentandworkuptocreatingyourownplug-in
editorsfortheEclipseenvironment.Hereareafewofthetopics
inthisbook:
UsingEclipsetodevelopJavacode
WorkingwithJARfiles
Settinglaunchconfigurations
SelectingJavaruntimes
CreatingJavadoc
Refactoring
ExtractingInterfaces
Viewingtypehierarchies
CustomizingEclipse
TestingcodewithJUnit
Debugging
Settingbreakpointhitcounts
Usinghotcodereplacement
SharingprojectswithCVS
Comparingcodewithlocalhistory
UsingAnttobuildEclipseprojects
GUIprogrammingfromappletstoSwing
UsingtheStandardWidgetToolkit(SWT)
SWTbuttons,text,labels,lists,layouts,andevents
SWTmenus,toolbars,sliders,trees,anddialogs
Developingwebapplications
Writingservletcodeinplace
UsingtheSysdeoTomcatplug-in
Debugginganddeployingwebprojects
DevelopingStrutsapplicationswithEclipse
UsingtheEasyStrutsplug-in
DevelopingEclipseplug-ins
ThePlug-inDevelopmentEnvironment(PDE)
Plug-inmanifests
Extensionpoints
UsingtheRun-timeWorkbench
Creatingastandardplug-in
Creatinganactionset
Creatingplug-inmenus
Creatingamultipageeditorplug-in
Creatingaplug-inwizard
CreatinganEclipseviewsupportedwithaplug-in
We'regoingtoseeallthesetopicsandmanymoreinthe
upcomingpages.Here'sanoverviewofeachchapter:
Chapter1
Thischapterisallaboutthebasics,includingallthedetails
ontheEclipseWorkbenchandanintroductiontotheJava
DevelopmentTools(JDT).
Chapter2
UsingtheJDT,we'regoingtocreateJavaprojects,create
codeautomatically,implementsyntaxchecking,andstart
developingsignificantJavaapplications.
Chapter3
AnIDEwouldn'tbemuchusewithoutadebugger.Eclipse
andtheJDTgiveyouallthepowerofatruedebugger,
includingbreakpoints,expressionevaluators,beingableto
changevaluesonthefly,andmore.
Chapter4
OneofthevaluableaspectsofEclipseisthatitletsyou
developinteams,somethingthatanycommercialdeveloper
canappreciate,sincesignificantdevelopmentisusually
doneinteams.UsingConcurrentVersionsSystem(CVS),
teammembersdoalloftheirworkintheirown
workbenches,buttheycanshareandregistertheirwork
usingaCVSrepository.
Chapter5
AntisapowerfulJavabuildtool,andwe'llseeinthis
chapterthatyoucandothingswithAntinEclipsethat
Eclipsecan'tdoalone,suchascopyandmovefiles.
Chapter6
ThischapterstartsourworkusingEclipsetohandleGUI
developmentwithSwing.We'llalsotakealookataSwing
plug-inforEclipsehereusingthisplug-in,forexample,you
candraganddropSwingcontrols.
Chapter7
Inthischapterandthenext,we'llbecoveringtheStandard
WidgetToolkit(SWT)theGUItoolkitforJavadevelopers
thatprovidesaportableAPIandtightintegrationwiththe
underlyingnativeGUIplatform.SWTa100%Java
alternativetotheAWTandSwingisanotherreasonEclipse
hasbecomesopopular,andwe'regoingtospendtwo
chaptersonit.
Chapter8
ThischaptercompletesourcoverageoftheSWT,including
dialogs,toolbars,sliders,trees,menus,andmore.
Chapter9
Thischaptergetsusstartedwithwebdevelopment,
creatingbothservletsandJSPusingEclipseandtheTomcat
server.We'llalsotakealookataTomcatEclipseplug-in.
Chapter10
Wecontinueourwebworkinthischapterwithapplications
constructedusingtheStrutsframework.We'llalsoseehow
touseaStrutsplug-in.
Chapter11
Inthischapter,we'regoingtostartcreatingEclipseplug-ins
toextendEclipse.We'llusethePlug-inDevelopment
Environment(PDE)andothertoolsinthischaptertocreate
workingplug-ins.
Chapter12
Here,we'regoingtogetthedetailsonsomemore
advancedaspectsofplug-increationeditors,creating
wizards,andhowtosupportEclipseviews.
Chapter13
Inthischapter,we'regoingtotakealookatEclipseVersion
3.0.Thiswillgiveyouaglimpseattheexcitingthingson
theEclipsehorizon.
ConventionsUsedinThisBook
Therearesomeconventionswe'llusethatyoushouldknow
about.Whenwe'veaddedanewpieceofcodeandare
discussingit,it'llappearinboldface,andwhenthere'smore
codetocome,you'llseethreedots.Here'swhatthatlookslike:
Listenerlistener=newListener(){
publicvoidhandleEvent(Eventevent){
ToolItemitem=(ToolItem)event.widget;
Stringstring=item.getText();
.
.
.
}
};
We'llalsousethestandardconventionforselectingmenuitems
inthisbook;forexample,tocreateanewprojectinEclipse,
youusetheFile New Projectmenuitem.
Thefollowingtypographicalconventionsareusedinthisbook:
Plaintext
Indicatesmenutitles,menuoptions,menubuttons,and
keyboardaccelerators.
Italic
Indicatesnewterms,exampleURLs,exampleemail
addresses,filenames,fileextensions,pathnames,
directories,andUnixutilities.
Constantwidth
Indicatescommands,options,switches,variables,types,
classes,namespaces,methods,modules,properties,
parameters,values,objects,events,eventhandlers,and
XMLtags.
Constantwidthitalic
Indicatestextthatshouldbereplacedwithuser-supplied
values.
Thisiconsignifiesatip,suggestion,orgeneralnote.
Thisiconindicatesawarningorcaution.
WhatYou'llNeed
Allthesoftwareyou'llneedinthisbookcanbedownloaded
fromtheInternetforfree.You'llneedEclipsethisbookwas
writtenusingEclipse2.1.1andwe'lldiscusswheretogetEclipse
inChapter1.Othersoftwarepackagesthatwe'llbe
downloadingthroughoutthebookincludetheTomcatweb
serverandvariousCVSservers(whichwillallowyoutoshare
Eclipseprojectswithothers).
Eclipseisbuilttobeextendible,andhundredsofEclipsepluginsareavailableforfreedownloading.Plug-insletyouadd
functionalitytoEclipsenewbuilt-ineditors,codegenerators,
softwarelaunchers,andmoreandwe'lltakealookatanumber
ofthemostpopularplug-insinthisbook.AndinChapter11
andChapter12,we'lldevelopourownEclipseplug-ins.
UsingCodeExamples
Allthecodeinthisbookisavailablefordownloadfrom
Seethefilereadme.txt
inthedownloadforinstallationinstructions.
Thisbookisheretohelpyougetyourjobdone.Ingeneral,you
mayusethecodeinthisbookinyourprogramsand
documentation.Youdonotneedtocontactusforpermission
unlessyou'rereproducingasignificantportionofthecode.For
example,writingaprogramthatusesseveralchunksofcode
fromthisbookdoesnotrequirepermission.Sellingor
distributingaCD-ROMofexamplesfromO'Reillybooksdoes
requirepermission.Answeringaquestionbycitingthisbook
andquotingexamplecodedoesnotrequirepermission.
Incorporatingasignificantamountofexamplecodefromthis
bookintoyourproduct'sdocumentationdoesrequire
permission.
Weappreciate,butdonotrequire,attribution.Anattribution
usuallyincludesthetitle,author,publisher,andISBN.For
example:"Eclipse,bySteveHolzner.Copyright2004O'Reilly
Media,Inc.,0-596-00641-1."
Ifyoufeelyouruseofcodeexamplesfallsoutsidefairuseor
thepermissiongivenabove,feelfreetocontactusat
We'dLiketoHearfromYou
Pleaseaddresscommentsandquestionsconcerningthisbookto
thepublisher:
O'Reilly&Associates,Inc.
1005GravensteinHighwayNorth
Sebastopol,CA95472
(800)998-9938(intheUnitedStatesorCanada)
(707)829-0515(internationalorlocal)
(707)829-0104(fax)
Wehaveawebpageforthisbook,wherewelisterrata,
examples,andanyadditionalinformation.Youcanaccessthis
pageat:
/>Tocommentorasktechnicalquestionsaboutthisbook,send
emailto:
Formoreinformationaboutourbooks,conferences,Resource
Centers,andtheO'ReillyNetwork,seeourwebsiteat:
Chapter1.EssentialEclipse
Ifyou'rereadingthisbook,you'remostlikelyaJava
programmer,andyouknowhowfinickyJavacanbeattimes.
Missedimportstatements,forgottenvariabledeclarations,
omittedsemicolons,garbledsyntax,typosalltheseproblems
willcausetheJavacommand-linecompiler,javac,tocoughin
yourfaceanddisplaypagesofannoyingerrormessages.The
errormessagestellyouthatjavacknowswhattheerroris,so
whydoesn'titjustfixtheproblemandletyougeton
developing?
Becausejavaccan'tfixtheproblem;itisn'taneditor.That
makeslongstreamsoferrorsscrollingoffthepageanall-toocommonexperienceforJavadevelopers,andleavesthemwith
thefeelingthatJavaistoopricklyaboutwhatcangowrong.To
changeallthat,youcanuseanintegrateddevelopment
environment(IDE),whichwillnotonlycatcherrorsbeforeyou
trytocompile,butalsosuggestsolutions.Javaisbadlyinneed
ofagoodIDE,andanumberofcandidatesareavailable,but
thepremiereJavaIDEthesedaysistheonethisbookisall
about:Eclipse.YoucanseeEclipseinactioninFigure1-1.
Figure1-1.Eclipse
1.1EclipseandJava
AlthoughEclipsecanactasanIDEformanydifferent
languagesIDEsareavailablefromC/C++toCobolitsgreat
popularityisasaJavaIDE,anditcomeswithJavasupport
built-in.Eclipsereferstoitselfasauniversaltoolplatform,
capableofhandlingIDEsformanydifferentlanguages,butthe
JavaIDEthatcomeswithEclipseisgoingtobeourmainfocus,
asitisforthegreatmajorityofEclipseusers.
ThewholeEclipsemagicisthatitwilltaketheroughedgesoff
Javadevelopmentinthewayyou'vealwaysimagined.The
errorsthatwouldcausejavactostumbleareusuallyhandled
beforeyoueventrytocompile,andifthereisanissue,Eclipse
willsuggestsolutions.Allyouhavetodoispointandclickno
needforserioushead-scratching.Ifyou'relikemostJava
developers,you'regoingtofindyourselfthinking,Thisisgreat!
1.1.1SomeBackground
Eclipseisfreeforthedownloading,likeanumberofotherJava
IDEs,butEclipsehasaseriousadvantagebehindit:thepower
ofIBM,whichreportedlyspent$40millioninthedevelopment
oftheIDE.Thefirstversion,Version1.0,appearedin
November2001andgraduallybecamepopular(althoughaswith
anydevelopertooltherewasagreatdealofdiscussionofits
faults).
Intime,Eclipsehaschangedandimproved,andthecurrent
version,2.1.1,isgettingmuchpraise.Infact,it'sbecomeso
popularthatwhenVersion2.1firstappeared,theserversat
weresobusythatitwasalmost
impossibletodownloadacopyforthefirstfewdays.
EclipsewascreatedbyIBMinamassiveeffortthathasleftJava
programmersthewinners.It'snowanopensourceproject,still
largelyunderIBM'sdevelopment,butpartofasoftware
consortiumnamedeclipse.org.Youcanseetheconsortium's
page,,inFigure1-2.
Figure1-2.TheEclipseconsortium'swebpage
TheEclipseconsortiumoriginallyconsistedofIBM'ssubsidiary,
ObjectTechnologiesInternational(OTI)whodevelopedEclipsein
thefirstplacealongwithBorland,IBM,MERANT,QNXSoftware
Systems,RationalSoftware3,RedHat,SuSE,TogetherSoft3,
andWebgain2inNovember2001.Sincethen,theconsortium
hasgrowntomorethan45members,includingSybase,Hitachi,
Oracle,Hewlett-Packard,Intel,andothers.
OTIisnotanewplayereither;it'sbeenaroundforquitesome
time,anditwasresponsibleforthefoundationsbehindIBM's
VisualAgelineofproducts(IBMacquiredOTIin1996).Long
ago,OTIcreatedaJavatoolwrittenintheSmalltalklanguage,
VisualAgeforJavaalsocalledVA4Jthatwaswellreceived.
EclipseitselfismoreorlessVA4JrewritteninJavaand
updatedmanyofVA4J'sidiosyncraticfeatureshavebeen
removedinfavorofmorestandardones,andagreatdealof
developmentpowerhasbeenadded.Inotherwords,although
Eclipseitselfisrelativelynew,italreadyhasconsiderable
history.
TheEclipseprojectasawholeisdividedintothreesubprojects:
TheEclipseplatformitself,whichformsthebackboneofthe
wholeapplication
TheJavaDevelopmentToolkit(JDT)
Theplug-indevelopmentenvironment(PDE),whichletsyou
developyourowntoolsforEclipse,calledplug-ins
Thesevarioussubprojectsarethemselvesdividedintoother
subprojectstheJDTsubproject,forexample,ismadeupofthe
userinterface(UI),core,anddebugsubprojects.Youcanlearn
moreaboutthesethreesubprojectsat
andofcourseyou'lllearnalot
moreabouttheminthisbook.
1.1.2AWordAbouttheCommonPublicLicense
(CPL)
Eclipseisopensourcesoftware,whichleavessomepeople
uncertainaboutlegalrightswhenusingit.Opensource
softwaregivesusersopenaccesstothesoftware'ssourcecode
andtherighttomodifyanddistributethesoftwarethemselves.
Ifyouwanttomodifythatsoftware,ontheotherhand,it's
oftentruethatopensourcelicensesdon'tallowdistributionof
themodifiedsoftwareunlesstheenduserisalsogiventhese
rights(asopposedtoacopyright,thisissometimescalleda
copyleftinopensourceprojects).
Someopensourcelicensesinsistthatanysoftwarebundled
withotheropensourcesoftwarealsobeopensource.However,
theopensourcelicensethatEclipseuses,theCommonPublic
License(CPL),isalsodesignedtoallowcommercialinterests.
TheCPLallowssoftwarebundledwithopensourcesoftwareto
bedistributedundermorerestrictivelicensesforcommercial
purposes.
Ifyoueverplantomodifyanddistributenewversionsof
Eclipse,youcanreadabouttheCPLat
(inparticular,at
Amongother
things,theCPLsays,"thislicenseisintendedtofacilitatethe
commercialuseoftheProgram."
That'sitfortheoverviewlet'sgetthisshowontheroad.
1.2GettingEclipse
HowdoyougetandinstallEclipse?Eclipseisfreeforthe
downloadingallyouhavetodoisnavigateto
andselectoneofthe
downloadmirrorsavailableonthatpage.Whenyoudo,you'll
bepresentedwithalistoftheavailabledownloads,whichareof
thesetypes:
Releasebuilds
TheEclipseteamreleasestheseversionsforgeneraluse.
UsuallywhenyoudownloadEclipse,you'lluseoneofthe
releaseversions.Thesebuildshavebeenthoroughlytested,
andthechanceofcomingacrossseriousbugsisminimal.
ThisisaversionofEclipsecomparabletotheversionthat
othercompanieswouldsellifEclipsewereforsale.
Stablebuilds
Thesearecomparabletobetaversions.Astablebuildisa
stepalongthewaytowardareleaseversion.TheEclipse
teamconsidersthisbuildtoberelativelystable,butthere
maybeproblems.Thisiswhereyou'llfindthenewfeatures
thatareupcominginEclipse.
Integrationbuilds
Thesebuildsaremadeupofcomponentsthathavebeen
fairlywelltested,buttheiroperationwithothercomponents
maystillhavesomeissues.IfthingsworkoutOKandthe