Saturday, 16 August 2014

Eclipse - Create Java Project

Eclipse - Create Java Project



Opening the New Java Project wizard

The New Java Project wizard can be used to create a new java project. There are many ways to open this wizard:
  • By clicking on the File menu and choosing New > Java Project
  • By right clicking anywhere in the Project Explorer and selecting New > Java Project
  • By clicking on the New button ( ) in the Tool bar and selecting Java Project

Using the New Java Project wizard

The New Java Project Wizard has two pages.
On the first page:
  • Enter the Project Name
  • Select the Java Runtime Environment (JRE) or leave it at the default
  • Select the Project Layout which determines whether there would be a separate folder for the sources code and class files. The recommended option is to create separate folders for sources and class files.

You can click on the Finish button to create the project or click on the Next button to change the java build settings.
On the second page you can change the Java Build Settings like setting the Project dependency (if there are multiple projects) and adding additional jar files to the build path.

Viewing the newly created project

The package explorer shows the newly created Java project. The icon that represents a Project is decorated with a "J" to show that it is a Java Project. The folder icon is decorated to show that it is a java source folder.


Eclipse - Workspaces

Eclipse - Workspaces



About Eclipse Workspace

The eclipse workspace contains resources such as:
  • Projects
  • Files
  • Folders
The workspace has a hierarchical structure. Projects are at the top level of the hierarchy and inside them you can have files and folders. Plug-ins use an API provided by the resources plug-in to manage the resources in the workspace.

UI Elements for Managing the Workspace

Users use the functionality provided by views, editors and wizard to create and manage resources in the workspace. One among the many views that show the content of the workspace is the Project Explorer view.

The File Wizard (File > New > File) can be used to create a new file.

The Folder Wizard (File > New > Folder) can be used to create a new folder.


Eclipse - Perspectives

Eclipse - Perspectives



What is a Perspective?

An eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective is active at any point of time. A user can switch between open perspectives or open a new perspective. The active perspective controls what appears in some menus and tool bars.

Opening a Perspective

To open a new perspective, click on the Windows menu and select Open Perspective > Other

The Open Perspective dialog box shows all the available perspectives.
The same dialog can be brought up by clicking on the Open Perspective button ( ) on the tool bar.

Switiching Between Perspectives

The most commonly used perspectives for java development are the Java perspective and Debug perspective. Users can switch between open perspectives by clicking on the Perspective name on the toolbar.

Closing a Perspective

To close a perspective, right click on the perspective name in toolbar and select the Close menu item.

Customizing a perspective

The customize perspective dialog can be used to customize a perspective. Customizing a perspective means:
  • Determining the icons visible on the toolbar when a perspective is active
  • Determining the menu items visible when a perspective is active
  • Determine the menu items in New submenu, Show View submenu and Open Perspective submenu


The Tool Bar Visibility tab can be used to determine which icons are visible on the toolbar when a perspective is open.
The Menu Visibility tab can be used to determine which menu items are visible when a perspective is active.
The Command Groups Availability tab can be used to control the visibility of toolbar icons and menu items.
The Shortcuts tab can be used to determine the menu items in New submenu, Show View submenu and Open Perspective submenu.
Based on the Shortcuts selection in the picture given below, to bring up the "New Java Project from Existing Ant Build File" wizard users have to bring up the New submenu (File > New), click on Other, expand the Java category and then select "Java Project from Existing Ant Build File". On the other hand to start the New Class wizard they can bring up the New submenu (File > New) and select the Class menu item becauses its selected in the picture given below. By selecting the "Java Project from Existing Ant Build File" check box this item will also appear under the New menu.


Eclipse - Explore Views

Eclipse - Explore Views



About Views

Eclipse views allow users to see a graphical representation of project metadata. For example the project navigator view presents a graphical representation of the folders and files associated with a project and properties view presents a graphical representation of an element selected in another view or editor.
An eclipse perspective can show any number of views and editors. All editor instances appear in a single editor area whereas views are placed inside view folders. A workbench window can display any number of view folders. Each view folder can display one or more views.

Organizing Views

The following picture shows four views arranged in a view folder.

The picture given below shows the same four views arranged in two view folders.

Moving views

To move a view from one view folder to another just click on the view title and drag to the title bar area of another view folder. The green line shown below is a result of dragging the title bar of the Properties view from one view folder to the title bar area of another view folder. The Properties view can be moved to where the green line is by releasing the mouse button and sending out a drop event.

Creating View Folders

View folders can be dynamically created by dragging the title bar of a view to anywhere outside the editor area and title bar of another view folder. As you drag the title bar around green lines will indicate where exactly the new view folder will be created.

Moving the drag icon to the bottom of a window allows you to create a view folder that spans the entire width of the window. Moving the drag icon to the left or right edge of window allows you to create a view folder that spans the entire height of the window.

Opening a view

To open a view click on the Window menu and select the Show View menu item and either the menu item that represent a view or the Other menu item.

Clicking on the Other menu item brings up the Show View dialog box that allows you to locate and activate a view.

The views are organized by category. To quickly locate a view just type the name of a view into the filter text box. To open a view, select it and click on the OK button.
The subsequent pages of this tutorial introduce you to a number of useful views.

Eclipse - Explore Menus

Eclipse - Explore Menus



Typical Eclipse Menus

The typical menus available on the menu bar of an Eclipse window are:
  • File menu
  • Edit menu
  • Navigate menu
  • Search menu
  • Project menu
  • Run menu
  • Window menu
  • Help menu


Plug-ins can add new menus and menu items. For example when the java editor is open you will see the Source menu and when the XML editor is open you will the Design menu.

Brief Description of Menus

Menu NameDescription
FileThe File menu allows you to open files for editing, close editors, save editor content and rename files. Among the other things, it also allows you to import and export workspace content and shutdown Eclipse.
EditThe Edit menu presents items like copy & paste.
SourceThe Source menu is visible only when a java editor is open. It presents a number of useful menu items related to editing java source code.
NavigateThe Navigate menu allows you to quickly locate resources and navivate to them.
SearchThe Search menu presents items that allow you to search the workspace for files that contain specific data.
ProjectThe menu items related to building a project can be found on the Project menu.
RunThe menu items on the Run menu allow you to start a program in the run mode or debug mode. It also allows presents menu items that allow you to debug the code.
WindowThe Window menu allows you to open and close views and perspectives. It also allows you to bring up the Preferences dialog.
HelpThe Help menu can be used to bring up the Help window, Eclipse Marketplace view or Install new plug-ins. The about Eclipse menu item gives you version information.

Customizing Menus

The visible menu items on a menu depend on the installed plug-ins and customization done using theCustomize Perspective dialog box.

Eclipse - Explore Windows

Eclipse - Explore Windows



Parts of an Eclipse Window

The major visible parts of an eclipse window are:
  • Views
  • Editors (all appear in one editor area)
  • Menu Bar
  • Toolbar
An eclipse perspective is the name given to an initial collection and arrangement of views and an editor area. The default perspective is called java. An eclipse window can have multiple perspectives open in it but only one perspective can be active at any point of time. A user can switch between open perspectives or open a new perspective. A perspective controls what appears in some menus and tool bars.
A perspective has only one editor area in which multiple editors can be open. The editor area is usually surrounded by multiple views. In general, editors are used to edit the project data and views are used to view the project metadata. For example the package explorer shows the java files in the project and the java editor is used to edit a java file.
The eclipse window can contain multiple editors and views but only one of them is active any given point of time. The title bar of the active editor or view looks different from all the others.
The UI elements on the menu bar and tool bar represent commands that can be triggered by an end user.

Using Multiple Windows

Multiple Eclipse Windows can be open at the same time. To open a new window, click on the Windows menu and select the New Window menu item.
Each window can have a different perspective open in them. For example you could open two Eclipse windows one in the Java perspective and the other in the Debug perspective. The window showing the Java perspective can be used for editing the java code and the window showing the debug perspective can be used for debugging the application being developed.

Eclipse - Installation

Eclipse - Installation



Downloading Eclipse

You can download eclipse from http://www.eclipse.org/downloads/. The download page lists a number of flavors of eclipse.
The capabilities of each packaging of eclipse are different. Java developers typically use Eclipse Classic or Eclipse IDE for developing Java applications.
The drop down box in the right corner of the download page allows you to set the operating system on which eclipse is to be installed. You can choose between Windows, Linux and Mac. Eclipse is packaged as a zip file.

Installing Eclipse

To install windows you need a tool that can extract the contents of a zip file. For example you can use:
Using any one of these tools, extract the contents of the eclipse zip file to any folder of your choice.

Launching Eclipse

On the windows platform, if you extracted the contents of the zip file to c:\, then you can start eclipse by using c:\eclipse\eclipse.exe
When eclipse starts up for the first time it prompts you for the location of the workspace folder. All your data will be stored in the workspace folder. You can accept the default or choose a new location.