An Introduction to Eclipse: Quick Guide Part 1: Getting Started with Eclipse Part 2: Working with Eclipse Useful Online Guides 1 1
Part 1: Getting Started with Eclipse Installation & Running The User Interface Creating a Project Creating a Class Running a Project Navigating Projects 2 2
Installation and Running Check java is present and up-to-date: java -version Download from http://www.java.com/en/download/manual.jsp Eclipse Enterprise Edition: http://www.eclipse.org/downloads/ Unzip and install (win: http://www.7-zip.org/ if needed) Run: windows: eclipse.exe linux / os x: eclipse application in the lab: Root > opt > eclipse-3.7 > eclipse 3 3
The User Interface Current Perspective Projects & Classes Editor Methods & Attributes Output 4 4
[right-click] Creating a New Project 1 2 3 4 5 5
Creating a Class 1 2 [right-click] right-click on the location / package where you want to place this class can auto-generate main method stub 6 6
Running a Project In Eclipse: From command line: Navigate to ProjectName/bin folder to execute If your project is packaged then from bin use java packagename/ classname to execute 7 7
Navigating Projects Selecting an item in one view brings it into focus in the other views 8 8
Part 2: Working with Eclipse Creating Packages Debugging Refactoring Creating jars Other Useful Features Automatic Code Generation Importing System Classes into Projects Importing System and User Libraries 9 9
Creating Packages 1 By convention these are named in mypackage style, just like classes 2 If you move classes between packages Eclipse will automatically fix references in other classes, and add import statements where needed 10 10
Automatic Code Generation Eclipse can automatically generate constructors and some frequently used methods With a class open in the Editor view, use the Source menu item as apt Hover on a problem notification to see the Quick Fix options: select one, then [control+enter] to invoke it can fix import declarations and most simple (non runtime) coding errors 11 11
Importing System Classes Problem: Types ArrayList and Color are not recognised Solution: Automatically import the classes 12 12
Importing Libraries 1 This adds a JRE System Library 2 3 For other libraries we select Add External Jars then navigate as apt 13 13
Debugging Red warnings are items that might cause the program to fail to run depends if the code is reachable Yellow warnings are advisory: attributes, methods and imports that are never used non-generic Collection types in use: such as ArrayList versus ArrayList<Integer> Hover on the warning for info, use Quick-Fix where apt Runtime errors can be traced from Console to the guilty line of code in Editor: click on the error to see the line in focus Visit http://www.ibm.com/developerworks/library/os-ecbug/ for a guide to the more advanced inbuilt debugging features 14 14
Refactoring Eclipse can rename methods and attributes across the whole scope of a project [double-click] on a method or attribute name > Refactor > Rename Optionally, old methods can be retained and deprecated: 15 15
Creating Jars JAR which includes source code (say for sharing work) [right-click] on project Export > Java > JAR File > Next select Export java source files and resources Name the JAR Runnable JAR (source code omitted, but includes externally referenced libraries) [right-click] on project Export > Java > Runnable JAR File > Next Select Launch Configuration: Extract External Files Name the JAR About Launch Configuration: Extract: external JARs will be extracted and the class files put/mixed together with your class files Package: external JARs will remain as JARs in the root of your archive 16 16
Other Useful Features To highlight the scope of { } parentheses, [double-click] just after the opening parenthesis Add // TODO comments to your code to manage work-inprogress View the TODO list using the Task view, NOT the Task List view Click on an item to bring it to focus in other views File Handling: the default working directory for files is the top level directory for the project, NOT the (src) directory containing the source code 17 17
Useful Online Guides (which also form the reference materials for this guide) Lars Vogel s Eclipse IDE Tutorial http://www.vogella.de/articles/eclipse/article.html David Scuse s guide to Eclipse 3.1 http://www.cs.umanitoba.ca/~eclipse/eclipse3-1.pdf Debugging with the Eclipse Platform http://www.ibm.com/developerworks/library/os-ecbug/ Eclipse Current Release User Guide http://help.eclipse.org/indigo/index.jsp Book/eBook: Eclipse IDE Pocket Guide by Ed Burnette (O Reilly Publishing) 18 18