Using File Search

When we have to search for a word in one or more projects, we use Eclipse File Search Feature. This feature enables us to search for specific words in specific file types. We can also search for a word in all the files by using the wildcard (i.e *). This is how we can use File Search:

1) Open Search->File from Menu Bar.

2) A dialog box will appear that will have many tabs. Currently the tab named File Search will be selected and opened.

3) In the containing text text field, enter the word to be searched.

4) If you want to search for this word in any specific file pattern, then put that pattern in File Name Patterns text box. If the word is to be searched in all the files, then use * there (As in the Screenshot).

Example: if I want to search for word “substitute” in file that ends with .properties extension, I will do the following:

5) You can select the Scope of the search by selecting a Radio Button in the Scope section.

6) If you want the search to be Case-Sensitive or according to Regular-Expression, then you can accordingly select the check boxes next to the Containing text Text box.

Tip: It’s a good practice to keep all the projects (except the one you are working on) closed. If any of the project is closed, then this utility will not search for the word in those projects.

Using the Search Result:

The search result will be shown in the Search view, which if not opened, will be opened automatically. The result will be shown in a hierarchical fashion like this:

Just above the hierarchy, the word and its occurrences in the workspace (or the Scope selected) are shown.

The various options present in the view are:

1) Show Next Match: Shows the next match for the word in the hierarchy.

2) Show Previous Match: Show the previous match for the word in the hierarchy.

3) Run the current search again: Runs the search with same parameters again.

4) Show Previous Searches: Displays a drop down list of Previous searches conducted in the current session.

Hope this article was helpful…..Keep on checking for more helpful posts….

Declaration View

Declaration View is very useful when we are working on big projects. At times we need to look at the declaration of various variables and definition of methods and classes. To do the same, we need to open the files in which the methods and classes are defined. Declaration view provides an alternative solution to this problem.

Declaration view provides the following information about the selected Element, where the Element can be a Variable, Class, Interface or Method:

  • Access Modifiers associated with the Element.
  • Other Information provided will vary depending upon the type of the Element. The various types possible are:
    • Variable: Shows the Declaration of the Variable.
    • Method: Shows complete Definition of the Method.
    • Class/Interface: Shows complete definition of the Class/Interface.

Configuring Local History

To know about Local History, read this Post.

Follow these steps to Configure Local History:

  1. Go to:

    Windows->Preferences

  2. Select

    General->Workspace->Local History

  3. Check Limit History Size if unchecked.
  4. Fill fields as needed:
    1. Days to keep files: It informs Eclipse about how many days you want to track the changes for.
    2. Maximum Entries Per File: Informs about how many changes are to be tracked. (Number of changes here means saving the file after modifying it).
    3. Maximum File Size (MB): Inform about the maximum file size. This file size corresponds to the file where all the changes are saved.
  5. Click on Apply/OK

Tasks View

Tasks view is a view using which we can track various tasks that we have to do. To know how to open the Tasks View, see this post.

There are two types of Tasks, Linked Tasks and unlinked Tasks.

Linked Tasks: Linked Tasks are tasks that are linked or related to a specific location or file. For Example, if you are working on some program and have to stop your work due to some reasons and want to remind yourself that you need to write some code at a specific location, you will use linked tasks.

In the Tasks view, when you double click on any Linked Task, it will open the file to which the task is linked and the cursor will be pointing to the line where the task was linked. Following are the methods of creating a Linked Task:

  1. Right Click the Ruler corresponding to the File/Line to which you want to link the task and select Add Task option.
  2. On the line where the Task is to be Linked, write:

// TODO Task To Be Done

This will also place the Task in the Tasks view, linking it with the line the Comment was written on, and will show Task To Be Done in Description Field.

Unlinked Tasks: Unlinked tasks are the tasks that are not related to any specific file or line. These are tasks of more General Nature. These tasks might Include, Mail Sam when Work is Over.

To add an Unlinked task, Right Click in the Tasks View and select Add Task.

Priority: We can define the priority of each task. Three available Priority levels are:

  1. High: Represented by an Red Exclamation Mark.
  2. Normal: No special symbols used.
  3. Low: Represented by an Arrow Facing Downwards.

Other Details that are shown in the Tasks View are:

  1. Description: This gives the description of the task.
  2. Resource: Gives the name of the file where the task is linked to.
  3. Path: Gives the absolute path of the File to which the task is related (minus the File Name).
  4. Location: Gives the Line Number of the related Line.
  5. Type: Gives the type of task.
  6. Priority: Inform about the task priority.
  7. Completion: Informs whether the task is completed or not.

Opening View

Even though Eclipse Perspectives are well decorated with all the views that we need for that perspective, some times we want to see things that are not present in the perspective. For Example, we might want to see the Tasks view in Java perspective. To solve this problem, we can open any view that we want to see despite of any perspective being open.

To Open a view, follow these steps:

Go to Windows->Show View

Here, without clicking, you will see a list of views that you can open. If the view you want to open is in the list, select it and it will open. If the view you want to see is not in the list, click on Other at the end of the list.

When you will click on other, a Dialog Box will open.In this dialog box, you can see list of all the views that are available for your Eclipse. Select the appropriate category and choose the view, or type something in Filter Text and filter the list of Views.

Adding Server to Eclipse

Eclipse don’t have any servers attached with it like NetBeans. Hence to use a server with it, we need to add a server to it. In this post I will show how to add a Tomcat Apache Server to Eclipse.

  1. Download Apache from http://tomcat.apache.org/.
  2. Install Apache.
  3. In Eclipse, open Java EE Perspective (see this Post) or open server view (see this Post).
  4. In Server View, Right Click and Select: New->Server.
  5. From the Dialog Box Opened, Select the Appropriate Server and Server Version (Apache in this case, version 7.0) and Click on Next.
  6. In the next dialog box, select the root directory for the server (the installation folder of the server). In case of Apache it will be, C:/Program Files/Apache Software Foundation/Tomcat 7.0
  7. Click on Finish and your server is associated with Eclipse.

Switching Perspectives

As I already informed about the use of perspectives in this post, here I will focus on how to change from one Perspective to others.

Our Eclipse comes with many perspectives. The perspectives present in it depends on the type of Eclipse you downloaded and the plugins that you have installed in it. Though some common perspectives like Java can be used most of the time, but in case if you want to add some extra pace and features in your working environment, you should surely switch between perspectives.

Default Perspective:

When we create a type of project for the first time, like Dynamic Web Project, or CVS Repository related project, Eclipse will prompt us that this task is related to some perspective. It will ask us if we want to switch to that perspective or not. It will also allow us to remember our decision. Check this button, and from next time,  when you will create a project of same type, you will get your perspective opened.

The default perspective option will also come when we will change the task. For example, if we are working in Java perspective, and then we start debugging, then Eclipse will again ask us if we want to switch to debug perspective.

Changing the Default Perspective:

To change the default perspective, you can go to

Windows->Preferences->General->Perspectives.

From the list of perspectives shown, select one perspective and click on Make Default Button.

Switching Between Perspectives:

On Top Right Corner of our workbench, just below the close button, you will find something written. This something maybe Java, Debug, J2EE etc. These are the names of the perspectives that we have. To change perspective from here, click on the Perspective name (if written) or click on the 2 arrows and a list of perspectives will come, select one from them. This list will contain only the perspectives that you have used before.

If you want to open a Perspective that is not at the Top Right Corner, you can do it from

Windows->Open Perspective Other->Select the Perspective and click open.

Editing A Perspective:

You can edit a perspective by opening it and then going to:

Windows->Customize Perspective

From here you can change following things:

  • Tool Bar Visibility: Change the options available on Tool Bar
  • Menu Visibility: Change the Menus in Menu Bar
  • Command Groups Availability
  • Shortcuts

At any time you can select reset Perspective to reset the Perspective to its default settings. This option is also available in Windows Menu.

Creating New Perspective:

To create a new perspective, you can select a Base perspective and then add or remove views from it or you can close all the perspectives and can then open various views that you want to be present in your Perspective. To see how to open views, see this post.

Once edited/created, you can save a perspective by using:

Windows->Save Perspective As

Enter a name and your perspective will be ready to be used. In case you will select an Existing perspective, or will type a name similar to that of an existing perspective, it will replace that perspective.

Adding New Features to Eclipse

If you have downloaded Eclipse from its official download page, then  you must have seen the various download options provided by Eclipse. You can download the type of Eclipse that you need. For Example, if I only work with Java SE then I will download Eclipse for Java Developers and not Eclipse for PHP Developers.

Every type or version of Eclipse will have its own features. Sometimes they might be adequate for us, but sometimes we need more features. For Example if I now decided to work with J2EE applications. I cannot use my normal Eclipse for it. So what will I do? Download Eclipse again? The Answer is No. And here is how to get more features in Eclipse.

  • From your Menu Bar select Help->Install New Software
  • A Window will Open. There will be a field in that window that will be labeled as Worl With.
  • In the text field next to this label, we mention the URL where we want to look for the feature that we want to install on our machine.
  • Normally there is a URL which is saved by the name of your Eclipse version, such as Helios for Eclipse 3.6, Indigo for Eclipse 3.7 etc.
  • This URL will look something like this, Helios – http://download.eclipse.org/releases/helios
  • Select this URL.
  • Now Eclipse will try to find the features available at this URL.
  • Once it will retrieve the data, it will show us all the features that we can install on our system.
  • Now select the feature you want to activate and click on next.
  • Eclipse will show us some more details about the feature, click on next/Finish.
  • If to install we have to accept some agreement, then an Agreement will be shown, else the feature will be installed directly.
  • Once the feature is downloaded and installed, we need to restart Eclipse.
  • When we will restart Eclipse, we will find the new Features inside it.

Just below the list of available features, there are some options which you can use as per your requirements. Following is the description of the same:

  • Show only the latest version of the software: Checking this option will ensure that whenever we install some feature, we are installing its latest version. Though if you want to install an older version of the same application, you can un-check this option.
  • Group Items by Category: This feature can be used if you want to view the features depending on their category. The category may look something like, Modelling, Web etc.
  • Contact all Update sites during install to find required software: In case if you are installing a software that may be present at more than one site and the sites are added in the list, then you can use this option. This will allow Eclipse to get the software from another site if one of the site is down.
  • Hide Items that are already installed: This option will hide the items already installed on our machine and hence reduces the confusion of what to install and what not to install.

ADD:

You can use this feature to add a URL for the plugin or feature you want to install. The URL can be a website, or a repository. If the feature is already on your machine, you can add it by using the Local or Archive options.

Understanding Eclipse Terminologies

Eclipse is an IDE for Java, and like all IDE’s provide us with a lot of facilities. But before getting in detail about how to use Eclipse, we should know about the various components of Eclipse. Following are components of Eclipse, with their description:

Eclipse

  1. Workbench: Workbench refers to the environment where our work will be done. An Eclipse workbench consists of Menu Bar, Tool Bar, Various Perspectives, Various Views and Editor.
  2. Menu Bar: Eclipse Menu Bar consists of various Menu Items that help us do the common things related to our working. Example could be: Run Menu, which is used to Run our application.
  3. Tool Bar: Eclipse tool bar consists of several shortcuts to do basic things. The item in the tool bar will depend on the perspective that is opened. For Example, in Java perspective, tool bar will have shortcut to create a class file, whereas in Java EE perspective, tool bar will have shortcut for creating JSP and Servlets.
  4. Perspective: Perspective is a set of tools and views that we use during our work. When we change our perspective, the views and the tools change according to our newly selected Perspective. We can have more than one Perspective in our Workbench, but at a time, only one perspective can be used or opened.

Note: To see how you can switch between perspectives, read this post.

   5.   Views: Views are small windows that are used to show useful information about our work. For Example, when we select a variable, the Declaration view will show the Declaration of the variable. Different perspectives have different views associated with them. For Example, in Java EE perspective, we will have server view, while in Java perspective we will have Console view.

      Note: To see how to enable and disable views, see this post.

6.   Editor: Editor is a special kind of view which is used to view and edit our data. It is used for editing source code. Editor also informs us about syntax errors that are present in our code.