Sei sulla pagina 1di 27

An Introduction to Eclipse

An Introduction to Eclipse:
Quick Guide

• Part 1: Getting Started with Eclipse

• Part 2: Working with Eclipse

• Part 3: Using Github with Eclipse

• Useful Online Guides


Part 1: Getting Started with Eclipse

• Installation & Running

• The User Interface

• Creating a Project

• Creating a Class

• Running a Project

• Navigating Projects
Installation and Running

• Check java is present and up-to-date: “java -version”

• Download from https://www.oracle.com/technetwork/java/javase/


downloads/index.html

• Eclipse: https://www.eclipse.org/downloads/packages/

• Unzip and install (win: http://www.7-zip.org/ if needed)

• Run:

• windows: eclipse.exe

• linux / os x: eclipse application


The User Interface Current
Perspective

Projects &
Classes
Editor

Methods &
Attributes
Output
Creating a New Project
1

3
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


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
Navigating Projects

Selecting an item in one view brings it into focus in the other views
Part 2: Working with Eclipse

• 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 fix references
in other classes, and add import
statements where needed
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
Importing System Classes
Problem: Types ArrayList and Color are not recognised

Solution: Automatically import the classes


Importing Libraries
1 This adds a JRE System Library

For other libraries we select “Add External


Jars” then navigate as apt
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
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:


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 About Launch Configuration:

• Export > Java > Runnable JAR File > Next Extract: external JARs will be
extracted and the class files put/mixed
• Select Launch Configuration: ‘Extract External Files’ together with your class files

Package: external JARs will remain as


• Name the JAR 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-in-


progress

• View the TODO list using the Tasks 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
Part 3: Using Github with Eclipse

• Adding a New Repository Location

• Adding, Moving and Removing Content

• Pull from Upstream

• Commit Changes

• Revert Changes

• Suggested Practice Exercise


Adding a New Repository Location
1
2
[right-click]

for more, visit:

https://github.com/collab-uniba/
socialcde4eclipse/wiki/How-to-import-a-
GitHub-project-into-Eclipse
Adding, Moving and Removing Content

• In Package Explorer View:

• Adding a new Folder (or File) to the repository:


• [right-click] on location > New > Folder (/File) > <choose name>

• Adding existing Files (including folders!):


• [right-click] on location > Import > File System > <browse as apt>

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

• Delete File:
• [right-click] on file > Delete

• In Github Repositories View:

• Adding existing Project:


• [right-click] on location > Import Projects… <browse as apt>
Pull from Upstream
1

2
Changes: Add to Index then Commit
1 2

3
Revert Changes (Locally)
Revert Changes (from Repository)
1
2

when the changes are historic or were done elsewhere


(and there is a lot more that can be done with Branches and Tags…)
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 repo

• go to Git Repositories perspective and refresh the view

• 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

• 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
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

• 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)

Potrebbero piacerti anche