Class Locator Overview

The Class Locator plug in allows a developer to configure a projects' classpath much more easily. Using it, the developer can add elements to the classpath based on the classes she needs. It is meant to eventually extend the standard auto completion and import system, by allowing auto inclusion of classes that are completely missing from the current classpath.

Tip: In order for ClassLocator to be usefull you need first to let it index the jar libraries available in your system. The places to look for jar files is called the "superset of class locations" and can be configured by selecting Window->Preferences from the main menu and then choosing the preferences for Class/Jar Locator. See Preferences for more info.

Main Features for this version

Why do you need it?

Auto completion and Auto import of classes have made the life of developers much better then before. When a needed class is in on the project's classpath, it is a breeze to find it and use it in source. A developer types the beginning of the class name and selects the class from the presented list - the rest is done IDE.

However, what if the class is not available yet on the classpath? What if the developer knows the name of the class but not which jar file includes it?

For example, let's assume a developer needs to reference Apaches' project Javah Ant Task, but none of the ant libraries are on the project's classpath. She wont get auto completion, nor would the class be automatically imported to her java file. More over, The whole project wont compile and many features like searching and refactoring will be disabled until she makea Javah available on the classpath.

Figure 1. Javah Class not available on the classpath

Alas, knowing which library exactly needs to be added is something easier said then done. In fact it is often tedious and error prone to do it. What if you could scan the hard disk for libraries containing Javah and then select one of those libraries from a list and then automatically add it to your classpath.?

Well, this is exactly what Class Locator can do for you. In fact it does even more, with a pre scanned cache. Just bring up the Class Locator Wizard by selecting Class Locator from the editor/project's context menu and type in the class name you need.

Tip: You can bring up Class Locator with the class name allready typed in for you. This is done by either selecting text in the editor and invoking the wizard from the editor's context menu, or copying text to the clipboard and invoking the wizard from another location (the menu/toolbar/project tree).

Once you see the class you need, select a class location from the list presented and type finish. That's it - Your classpath is set and you can continue to work.

Figure 2. Class Locator wizard in invoked and find the location of Javah

Once Finish is clicked (a location must be selected from the bottom list for the finish button to be enabled), the process of updating the project's classpath begin. This includes checking if the selected location is already on your classpath (in any form: directly, as a classpath variable or an extension of a classpath variable). If the location is indeed missing from the classpath, Class Locator looks for an existing classpath variable corresponding to the location. When one is found, Class Locator insert it to the classpath.

However, if no classpath variable exits in the IDE to suite the requested path, Class Locator generates a unique variable name suitable for the location (collision with another variable name is avoided by generating new names until a unique one is found). Then a new and generally available classpath variable is created with the needed name and location and inserted into the current project classpath.

Figure 3. OPTIONAL_JAR classpath variable is added to the classpath

 

Figure 4. OPTIONAL_JAR inserted automatically is a geenrally available classpath variable

 

Figure 5. Javah now available for auto completion and import

 

How does it work

The idea behind the Class Locator is simple. The developer defines a superset of all locations to search in (see Setting the Preferences). The superset of locations is expended by recursively for jar file residing in the locations specified. The classes in the extended superset are indexed and the index is save.

Once the developer needs to locate a class and include its location in her classpath, she invokes the wizard and types in the name of the needed class or the some part of it. The wizard uses the index of the superset of locations to find locations where this class is available, this can be jar files and directories. The developer selects a location and clicks the finish. The location is now available on the classpath and the developer can continue with her real work.

Plans for the future

  1. Integrate into the IDE's auto completion scheme and allow (using a different key binding) to search for classes from within the editor, without the need to use the wizard.
  2. Make the creation and usage of classpath variable configurable.

 

Copyright (c) 2002 Dani Kenan. All right reserved.