Eclipse plug-in development Quick Start

Source: Internet
Author: User
Tags simple xml editor

This article was reproduced by Skynet. Thank you. Address:

Eclipse is a very popular Java integrated development environment (IDE). It is a strong competitor of NetBeans/SunOne Studio, Jbuilder, and IntelliJ IDEA. The Java programmer group is rapidly migrating to Eclipse because it is free, open-source, of good quality, and very easy to customize.

This article describes how to compile plug-ins in Eclipse ). Who are the target readers of this article? Many Eclipse users simply use the IDE without customization. Many users use plug-ins built by others, which are not the target readers of this article. Some users want to customize Eclipse, some will develop tools for their employees, and some want to sell tools related to their own products; some people want to use other names to resell the Eclipse with some pre-installed tools. These members form the target audience of this article. The prerequisite for writing Eclipse plug-ins is to understand how to use Eclipse and write Java programs, and have a good understanding of the Standard Widget Toolkit (SWT.

  Install Eclipse

If you have already used Eclipse 3, you can skip this section. If the software is not installed, You need to download and install it first. You can download the latest stable version from the Eclipse download page and decompress the downloaded file to a folder (for example, c:/dev ). When writing the text, this file is (85 MB ). In this process, the c:/dev/eclipse folder is created.

Note that there is already a folder named plugins under this folder. You can quickly browse and find many installed plug-ins. What's going on? Because Eclipse has a relatively small core, almost every part is a plug-in.


Eclipse consists of a small core and a large number of plug-ins on the core. Some plug-ins are only used by other plug-ins. There are many tools you can use. The basic libraries used by all plug-ins are:

· Standard Widget Toolkit (SWT): graphical components used everywhere in Eclipse: buttons, images, cursors, labels, and so on. Layout management class. This library is usually used to replace Swing.

· JFace: menu, toolbar, dialog box, parameter selection, Font, image, text file class and Wizard base class.

· Plug-in Development Environment (PDE): a class that assists in data operations, expansion, creation processes, and wizard.

· Java developer kit (JDT): A class used to program and operate Java code.

Each of the above classes has its own proprietary functions, some of which can be used independently (although they depend on other classes internally ). For example, SWT is not only used for plug-ins; it can also be used to build non-Eclipse, independent applications. Some other libraries are not listed.

Figure 1 shows the relationship between different levels of Eclipse.

Figure 1 hierarchical class library

  Install GEF and Draw2D

By default, these two object-oriented libraries (GEF and Draw2D) are not installed. We need to use them in this article, so we need to install them first. Your bandwidth (5.5 MB ). Decompress the file to the Eclipse folder (this is a folder containing the plugins subfolder ). These two libraries are also added as plug-ins.

What functions are provided by these libraries? They constitute the basis for creating graphical plug-ins. Graphical plug-ins usually display some objects (such as boxes and labels, which are linked together with lines and arrows ). The drawing of these objects and connectors is handled by Draw2D. However, the rendering process is only half of the functions implemented by the Graphical Editor. The other half-Editor commands, tool bars, drag-and-drop functions, and printing-are completed by GEF.

  Configure the pdpa Option

After installing the above components, the next step is to customize or at least be familiar with the plug-in configuration options. These options are selected under the "plug-in development" category of the menu form> option. View the dozens of configuration options used by the plug-in. You can take a look at the Target Environment (Target Environment) category. It allows us to select the default operating system, Windows system, CPU architecture and language.

We are also interested in the Plug-in Development (Plug-in Development) perspective (perspective is a set of view Parameter options, including panels, views, tool bars, and so on, which change according to different transactions, you can see the "pattern" in Eclipse "). Choose "window"> "open perspective"> "Others" in the menu, and select "plug-in development" in the list to see it. It is similar to the Java perspective, but has a plug-in view that can display all detected plug-ins. Figure 2 shows how to activate the perspective and shows the perspective.

Figure 2: plug-in development perspective
  Create a Simple plug-in

The easiest way to create a plug-in is to use the template provided by the file-> New-> plug-in Project Wizard. Enter a project name (for example, "Invokatron "). What does this mean? The plug-in we will create is Invokatron, which is a graphical editor for generating code for Java code. This article deletes the Invokatron path, but it is clear that this ambitious project will not be completed until the next installation.

On the "Next" Page, all the other options except the class name remain unchanged. The class name is invokatron. InvokatronPlugin. On the "plug-in content" Page, enter any information that you think is appropriate. On the "template" Page, select the check box to activate the template. We can select from multiple templates:

· Hello, World

· Simple XML editor

· Multi-page editor and Wizard

· Perspective Extension

· Pop-up menu

· Attribute page

· View

· Custom plug-ins with one or more previous data items

For the example in this article, we use a custom plug-in template. Select "Multi-page editor"-"New File wizard"-"properties. Enter the following values on the "Next" Page:
"Multi-page editor" Page (Figure 3 ):

· Java package name: invokatron. editor

· Editor Class Name: InvokatronEditor

· Editor auxiliary class name: InvokatronEditorContributor

· Editor name: Invokatron Editor

· File Extension: invokatron

Figure 3: "Multi-page editor" Settings

"New wizard" Page (figure 4 ):

· Java package name: invokatron. Wizard

· Wizard category ID: invokatron

· Wizard category name: invokatron wizard

· Wizard class name: invokatronwizard

· Wizard Page Class Name: invokatronwizardpage

· Wizard name: invokatron wizard

· File Extension: invokatron

· Initial file name: myclass. invokatron

Figure 4: "New wizard" Settings

"Properties" Page (figure 5 ):

· Java package name: invokatron. Properties

· Property page class: invokatronpropertypage

· Property page name: invokatron Properties

· Target class: org. Eclipse. Core. Resources. ifile

· File name filter :*.*

Figure 5: "attribute" page settings

At this time, eclipse generates a large number of files:

· Plugin. xml: describes the main file of the plug-in. It contains information about auxiliary code generation, libraries, plug-in dependencies, and extensions.

· Build. properties: A file used to describe the build process. It is mainly used to specify the required database.

· Invokatron/*. Java: plug-in class.

· Sample.gif: the icon displayed in the menu item.

The plugin. xml file and build. properties are displayed in the Multi-page editor together. The first page ("preview") allows you to export and run the plug-in the test environment. "Export" means to improve the plug-in by generating some code, then compiling and packaging.

Check the class and you will find that it does not actually perform any operations. Where is the code for adding menu options? The framework component generates necessary code from the information contained in the plugin. xml file. You can check this file. Its last part contains an extension list, which is the place where these classes can be inserted into Eclipse.

The project generated in the above process is part of the sample code. You can download it.

  Run and debug

You can test your plug-in a special sandbox-runtime workbench. In this way, Eclipse can still work even if the workbench crashes during running. Click the "load runtime workbench" or "load runtime workbench in debug mode" link on the "preview" page. When you run the workbench for the first time, the eclipse/runtime-workbench-workspace folder is created. It starts a new Eclipse instance, which is very similar to the normal Eclipse window (except that your plug-in can be used ).

But you should first select File> New> Project menu and Java project to create a Java project. The project name is Test. Figure 6 shows the runtime workbench with the created wizard and editor.

Figure 6: run the plug-in

Now let's take a look at the Invokatron wizard. You can see it from the menu File> New> others. View the class Invokatron wizard. Select the Invokatron wizard and click "Next ". This wizard will create an empty Invokatron document. In the Container field, select the Test project and click "finish ". A new Invokatron editor is displayed. This editor has three pages: a text editing page, an attribute page (font selection), and a preview page (sorted and drawn in the selected font ).

  Supported files

You can specify the files required by your plug-in during compilation and running in many locations. This makes these Eclipse users very confused. We are trying to clarify these issues.

Supported files are classified into three types:

1. Classes and resources from the plug-in Code itself. They are packaged into one or more. jar files during creation.

2. Classes and resources required for compiling and running plug-ins. They should all be included in the class path, and we must specify that these files need to be copied during export.

3rd. A file included with the plug-in (such as the readme.txt file ). They are not in the class path.

You can set the compiling environment on the "Build" page of the plug-in editor. In addition, these settings are mapped to the build. properties file. We may be confused when we first see this page, because it has four separate parts:

· Runtime information: lists the generated library files (1st class files ). Generally, a library file contains all the classes required by the plug-in, but you may want to split it into smaller blocks.

· Source Build: Lists class files that should be included in the. jar file (1st class file input)

· Binary Build: list the files that should be copied to the exported plug-in folder or file files (3rd class files ). When the above selection box is selected, the generated file will be automatically included.

· Precise class path items: lists the. jar files required by your application at the time of compilation (class 2nd files ). These files are automatically added to your project library. A common mistake is to include a. jar file in "Java build path" on the "properties" page and in this list.

If your plug-in uses a special library, you must ensure that the library is added to the project. Add it to Source Build and precise class path items.

Other important property pages of the plug-in Editor include:

· Dependencies: If your plug-in depends on other plug-ins, you must specify them here.

· Runtime: on this property page, you can specify special actions for the plug-in.


After the plugin code is completed and tested in the workbench, you should prepare and deploy it to the "real" Eclipse environment. To implement this step, return to the "preview" Page and click the "Export wizard" link. The "export options" dialog box allows you to select one of the three deployment types:

· Directory structure: deploy the file to a directory for Eclipse to use immediately. Then you can set the Destination location (Destination) to a local Eclipse folder (for example, c:/dev/eclipse) and directly use the plug-in.

· Single. ZIP file: The same folder will be compressed into a. ZIP file, ready for release to the customer. Next, you must extract the file to the top-level folder of Eclipse to install the plug-in. Specify the. ZIP file name in the file name field.

· Independent. jar file used by the Update site: generate a. jar file compatible with Eclipse for automatic update system.

After you click "finish", the selected output is generated. If you use the output as the directory structure, you must restart Eclipse to activate the plug-in.

  View examples and source code

The best source of information about how to compile Eclipse plug-ins is the plug-in sample set provided by Eclipse. If I have to select only one information source to assist myself in writing the plug-in, I must select it.

To download these plug-ins, you only need to visit the Eclipse download page and select the latest version. In the middle of the page, there is a "sample plug-in". Download The. ZIP file (less than 2 MB ). Decompress these files to the Eclipse folder (for example, c:/dev. This step will create many folders under eclipse/features and eclipse/plugins. The source code of these examples is shown in the. ZIP file in the C:/dev/eclipse/pluginsfolder as follows:

Example Code Location
SWT example In the org. eclipse. sdk. examples. source_3.0.1/src... folder
· Address book
· Clipboard
· File Viewer
· Hello World
· Floating help
· Image analyzer
· Java syntax Viewer
· Text Editor
.../Org. eclipse. swt. examples_3.0.0/ integrated with the workbench
· Browser .../Org. eclipse. swt. examples. browser_3.0.0/
· Controls .../Org. eclipse. swt. examples. controls_3.0.0/
· SWT Loader .../Org. eclipse. swt. examples. launcher_3.0.0/
· Layout .../Org. eclipse. swt. examples. layouts_3.0.0/
· Drawing .../Org. eclipse. swt. examples. paint_3.0.0/
· OLE Special Folder:
Org. eclipse. sdk. examples. source. win32.win32. x86_3.0.1/src/org. eclipse. swt. examples. ole. win32_3.0.0/
Workbench example  
· Java Editor .../Org. eclipse. ui. examples. javaeditor_3.0.0/
· Template editor .../Org. eclipse. ui. examples. javaeditor_3.0.0/
· Multi-page editor .../Org. eclipse. ui. examples. multipageeditor_2.1.0 </
· Attribute Table .../Org. eclipse. ui. examples. propertysheet_2.1.0/
· Readme Tool .../Org. Eclipse. UI. Examples. readmetool_2.1.0/
Help example Special Folder: Java file is stored in
Team example  
· Knowledge Base provider
· Synchronous sharing
.../Org. Eclipse. Team. Examples. filesystem_3.0.0/
File comparison example  
· Structure comparison .../Org. Eclipse. Compare. examples_3.0.0/
· XML comparison .../Org. Eclipse. Compare. Examples. xml_3.0.0/

There are also some useful examples of GEF and Draw2D plug-ins. You can access the GEF page and download the latest version. The version release page contains the "GEF example". Download The. ZIP file. When writing a text, the file is (0.5 MB ). Decompress the file to the folder where Eclipse is located. You will see the following two examples:

Example Code Location
· Logical chart example Org. Eclipse. GEF. Examples. source_3.0.1/src/org. Eclipse. GEF. Examples. logic_3.0.0/
· Streaming chart example Org. Eclipse. GEF. Examples. source_3.0.1/src/org. Eclipse. GEF. Examples. flow_3.0.1/

  Find plug-in Development Information

The first check point is the example in the previous section. The second is the help system, which has a very high quality. The related content is as follows:

· Platform Plug-in development

· JTD plug-in development

· Guidance on the de-RDE

· Draw2D developer Guide

· GEF developer Guide


Now you have enough information to create an Eclipse graphical plug-in. With the help of so many class libraries, only your imagination will limit your actions. The secret is that you need to know which tools you can use and use the right tools to complete the appropriate work.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.