Hello World Eclipse Plugin Project

To create eclipse plugins, you need an eclipse distribution package with Eclipse Plug-in Development Environment like Eclipse Standard or Eclipse IDE for Java EE. I am using Eclipse Standard 4.3.2. Always try to use the latest version of the distribution available. You can start exploring from eclipse site at http://www.eclipse.org/downloads to check the package contents of the distribution package. Once the correct distribution package is downloaded, extract and run eclipse.exe (Windows), eclipse (Linux), or Eclipse.app (OS X) to start eclipse, selecting a workspace folder to store your project files. The workspace folder will be created if not already present.

To create eclipse plugins using eclipse, we need to create a Plug-in Project first. Navigate to File > New > Project > Plug-in Project (under Plug-in Development) to start the New Plug-in Project wizard. You can also navigate as File > New > Other > Plug-in Project (under Plug-in Development). You can also upgrade an existing Java project to a plug-in project by navigating to Configure > Convert to plug-in project, but here we will only see how to use New Plug-in Project wizard. The Eclipse-developed plugin names usually start with org.eclipse (e.g. org.eclipse.ui). After the New Plug-in Project wizard starts, enter project name following the convention (e.g. com.javajee.eclplugin.hello). According to eclipse naming conventions all plug-ins must have unique identifiers similar to the naming convention of Java packages. Leave other entries and selections with their defaults, and click next until you reach Templates page. In the Templates page, select “Hello, World”, click next, make any changes to messages and click finish. This template adds a Sample Menu to the menu bar and a button to the tool bar, and both of these invoke the same Sample Action which will open a simple message dialog with a message you just configured.

Previous steps will create a sample plugin project which you can modify to add more features. To run this project, right click the project and run as ‘Eclipse Application’. A new eclipse instance will be launched with this plugin. Since we used the “Hello, World” template, you should see a new Menu called ‘Sample Menu’. Navigate to Sample Menu> Sample Action and you should see a dialog with the message you had configured. Now you can explore the created project and try to make some changes like changing the message etc.

 

A quick look into the auto generated files

Three key files generated are META-INF/MANIFEST.MF, plugin.xml and build.properties.

The MANIFEST.MF describes the plug-in's name, version, dependencies etc.

Manifest-Version: 1.0

Bundle-ManifestVersion: 2

Bundle-Name: Hello

Bundle-SymbolicName: com.javajee.eclplugin.hello;singleton:=true

Bundle-Version: 1.0.0.qualifier

Bundle-Activator: com.javajee.eclplugin.hello.Activator

Bundle-Vendor: JAVAJEE

Require-Bundle: org.eclipse.ui,

 org.eclipse.core.runtime

Bundle-RequiredExecutionEnvironment: JavaSE-1.7

Bundle-ActivationPolicy: lazy

 

The plugin.xml file declares what extensions this plug-in provide to the Eclipse runtime. Non-UI plug-ins often doesn’t need to have plugin.xml file.

<?xml version="1.0" encoding="UTF-8"?>

<?eclipse version="3.4"?>

<plugin>

   <extension

         point="org.eclipse.ui.actionSets">

      <actionSet

            label="Sample Action Set"

            visible="true"

            id="com.javajee.eclplugin.hello.actionSet">

         <menu

               label="Sample &amp;Menu"

               id="sampleMenu">

            <separator

                  name="sampleGroup">

            </separator>

         </menu>

         <action

               label="&amp;Sample Action"

               icon="icons/sample.gif"

               class="com.javajee.eclplugin.hello.actions.SampleAction"

               tooltip="Hello, Eclipse world"

               menubarPath="sampleMenu/sampleGroup"

               toolbarPath="sampleGroup"

               id="com.javajee.eclplugin.hello.actions.SampleAction">

         </action>

      </actionSet>

   </extension>

</plugin>

Text labels (e.g. Sample Action) for the commands, actions and menus, tooltips etc. are represented in the plugin.xml file and hence Eclipse can show the menus before loading or executing any code. Try changing these values and run as eclipse again.

The build.properties file contains reference to resources used and is used mainly during development and build process.

source.. = src/

output.. = bin/

bin.includes = plugin.xml,\

               META-INF/,\

               .,\

               icons/

Just double click in eclipse and use the Build tab in Build Configurations to edit this file.

 

References

http://wiki.eclipse.org/Naming_Conventions#Plug-ins_and_Extension_Points

Book: Eclipse 4 Plug-in Development by Example Beginner's Guide by Dr Alex Blewitt.

Tags: 

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (52) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (8) Javascript Frameworks (1) Java SE Professional (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) resources (1) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)