Introduction
Eclipse provides programmers with powerful text-search capabilities that allow programmers to easily search the workspace for JAVA code or text that is needed. But sometimes, programmers want to search for a string in a. class file source code or plain text file that is contained in a Jar file, and Eclipse cannot meet the requirements. For example, a user trying to find the definition of a string that appears on the UI needs to search in the generic text file in the Jar file, as well as the. class file source. These Jar files are included in the project Classpath, which is often required in RCP development, and Eclipse is not yet providing this feature. This article solves this problem by using the interface associated with the Jar in JDT (Java Development Toolkit), and gives examples and procedures for presentation.
The principle of search in Eclipse
Eclipse uses the Lucene technology to develop its search kernel, which quickly locates target files by indexing keywords. For example, Eclipse will index the class name, field name, method name, and so on in the JAVA source file, and when the programmer uses the Open type feature (accelerator: ctrl+shift+t) to perform a class search, it can be searched quickly by using the index field of the class name; When using the Java Search feature, Eclipse also lets the user specify a specific index field (search for), such as the method name, class name, field name, package name, constructor name, and so on, depending on the index field you select and the user's input, Quick Search to source code.
Eclipse's limitations in providing search for Jar source code
Eclipse provides a file search feature that searches for text files within a specified range (project, workspace, and so on). This feature is not indexed according to some special keywords. Because of the search for any string, it is not possible to find a specific keyword to index. Therefore, in order to improve search efficiency, Eclipse has limited the search scope for any string to a user-written text file, without searching for the source code of the classes in the Jar file on which the project depends. Because the number of Jar source code is often large, searching for them will be a rather time-consuming operation. However, in many cases, it is necessary for programmers to search for source code, to address some of the problems by looking at the required source, and the search capabilities that Eclipse currently offers do not meet this requirement.
Analysis of the class structure diagram related to Jar file in JDT
The following two diagrams show the classes associated with Jar file processing in JDT, from which you can clearly understand their levels, inclusions, and correspondence.
Figure 1. UML class structure diagram related to Jar file in JDT
Figure 2. Diagram of class structure associated with Jar file in JDT