You are on page 1of 28

An Introduction to Eclipse: Quick Guide

Part 1: Getting Started with Eclipse Part 2: Working with Eclipse Part 3: Using Subversion (SVN) Useful Online Guides

Tuesday, 9 October 12

Part 1: Getting Started with Eclipse

Installation & Running The User Interface Creating a Project Creating a Class Running a Project Navigating Projects

Tuesday, 9 October 12

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:


Tuesday, 9 October 12

windows: eclipse.exe linux / os x: eclipse application in the lab: Root > opt > eclipse-3.7 > eclipse

The User Interface


Projects & Classes

Current Perspective

Editor

Methods & Attributes

Output

Tuesday, 9 October 12

Creating a New Project


1
[right-click]

Tuesday, 9 October 12

Creating a Class
1
[right-click]

right-click on the location / package where you want to place this class can auto-generate main method stub

Tuesday, 9 October 12

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

Tuesday, 9 October 12

Navigating Projects

Selecting an item in one view brings it into focus in the other views

Tuesday, 9 October 12

Part 2: Working with Eclipse



Tuesday, 9 October 12

Creating Packages Automatic Code Generation Importing System Classes into Projects Importing System and User Libraries Debugging Refactoring Creating jars Other Useful Features

Creating Packages
1
By convention these are named in myPackage style, just like classes

If you move classes between packages Eclipse will automatically x references in other classes, and add import statements where needed

Tuesday, 9 October 12

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 notication to see the Quick Fix options:

select one, then [control+enter] to invoke it can x import declarations and most simple (non runtime) coding errors

Tuesday, 9 October 12

Importing System Classes


Problem: Types ArrayList and Color are not recognised

Solution: Automatically import the classes

Tuesday, 9 October 12

Importing Libraries
1
This adds a JRE System Library

2 3

For other libraries we select Add External Jars then navigate as apt

Tuesday, 9 October 12

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

Tuesday, 9 October 12

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:

Tuesday, 9 October 12

Creating Jars

JAR which includes source code (say for sharing work)


Tuesday, 9 October 12

[right-click] on project Export > Java > JAR File > Next select Export java source les 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 Conguration: Extract External Files Name the JAR
About Launch Conguration: Extract: external JARs will be extracted and the class les put/mixed together with your class les Package: external JARs will remain as JARs in the root of your archive

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 les is the top level directory for the project, NOT the (src) directory containing the source code

Tuesday, 9 October 12

Part 3: Using Subversive (SVN)



Tuesday, 9 October 12

Installing Subversive Adding a New Repository Location Adding, Moving and Removing Content Sharing a Project Check Out Files and Folders Commit Changes Revert Changes Suggested Practice Exercise

Installing Subversive

visit: http://www.eclipse.org/subversive/documentation/ gettingStarted/aboutSubversive/install.php general guidance: http://www.eclipse.org/subversive/ documentation/index.php

Tuesday, 9 October 12

Adding a New Repository Location


1 2

Tuesday, 9 October 12

Adding, Moving and Removing Content



In SVN Repository Exploring View: Adding a new Folder to the repository:


Tuesday, 9 October 12

[right-click] on location > New > Folder > <choose name>

Adding existing Files (including folders!):


[right-click] on location > New > File > <browse as apt>

Move File:
[select-and-drag] as apt

Delete File:
[right-click] on le > Delete

Sharing a Project
1 2 3

do in Java view must refresh the SVN view to see it there easy to change projects location in SVN view
Tuesday, 9 October 12

Check Out Files & Folders

Tuesday, 9 October 12

Commit Changes

always make a comment


Tuesday, 9 October 12

Revert Changes (Locally)

when the changes have happened within this session

Tuesday, 9 October 12

Revert Changes (from Repository)

when the changes are historic or were done elsewhere

Tuesday, 9 October 12

Suggested Practice Exercise



create a simple project in Eclipse

a couple of classes will do then make a backup copy outside of your Eclipse workspace folder

share it to the team repository go to SVN Repository perspective and refresh the view move the project into sandbox delete the local copy of the project from your Eclipse workspace

check the box to also delete contents on disc

now check out the project from the repository just the project, not the whole repository

go to Java perspective and make trivial changes to the code commit the changes try having a couple of team members simultaneously make changes (to different classes) in the project

Tuesday, 9 October 12

Useful Online Guides


(which also form the reference materials for this guide)


Tuesday, 9 October 12

Lars Vogels Eclipse IDE Tutorial

http://www.vogella.de/articles/Eclipse/article.html

David Scuses 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 (OReilly Publishing)

You might also like