Brief Description:
Test how to make a plugin for eclipse
Reference:
"In-depth understanding of Java virtual machines"
April 2012 1th Edition, 6th time printing
Page 116
Project Download Address
Http://pan.baidu.com/s/1mg8yi1a
steps:
1. Create a new plug-in project
Launchinfo
Project structure:
2. Interface
Launchplugin.java
Package com.anialy.launch_plugin;
Public interface Launchplugin {public
void Showonlaunch ();
}
3. Implement
Launchpluginimpl
Package Com.anialy.launch_plugin.impl;
Import Org.eclipse.jface.dialogs.MessageDialog;
Import Org.eclipse.swt.widgets.Display;
Import Org.eclipse.swt.widgets.Shell;
Import Com.anialy.launch_plugin. Launchplugin;
public class Launchpluginimpl implements launchplugin{public
void Showonlaunch () {
display.getdefault (). Syncexec (New Runnable () {
@Override public
void Run () {
Long eclipselaunchtime = Long.parselong (
System.getproperty ("Eclipse.starttime"));
Long costtime = System.currenttimemillis ()-eclipselaunchtime;
Shell shell = Display.getdefault (). Getactiveshell ();
String message = "Eclipse startup time:" + costtime + "MS";
Messagedialog.openinformation (Shell, "Info", Message);}}
);
}
}
4. Configuration
Plugin.xml
<?xml version= "1.0" encoding= "UTF-8"?> <?eclipse
version= "3.4"?>
<plugin>
< Extension
point= "Org.eclipse.ui.startup" >
<startup class= "Com.anialy.launch_plugin. Launchplugin "/>
</extension>
</plugin>
Activator.java
Package com.anialy.launch_plugin.startup;
Import Org.eclipse.jface.resource.ImageDescriptor;
Import Org.eclipse.ui.plugin.AbstractUIPlugin;
Import Org.osgi.framework.BundleContext; /** * The Activator class controls the plug-in life cycle */public class Activator extends Abstractuiplugin {//the Plug-in ID public static final String plugin_id = "Lauchinfo";
$NON-nls-1$//The shared instance private static Activator plugin; /** * The constructor * */Public Activator () {}/* * (non-javadoc) * @see Org.eclipse.ui.plugin.AbstractUIPlug In#start (org.osgi.framework.BundleContext) */public void Start (Bundlecontext context) throws Exception {Super.start
(context);
plugin = this; }/* * (non-javadoc) * @see org.eclipse.ui.plugin.abstractuiplugin#stop (org.osgi.framework.BundleContext) */Publ
IC void Stop (Bundlecontext context) throws Exception {plugin = null;
Super.stop (context); }/** * Returns the shared instance * * @return the SharEd instance */public static Activator Getdefault () {return plugin; }/** * Returns an image descriptor for the image file at the given * plug-in relative path * * @param path the Path * @return The image descriptor */public static imagedescriptor Getimagedescriptor (String path) {return image
Descriptorfromplugin (plugin_id, path);
}
}
5. Export as jar (default to Workspce folder)
6. Right-click Project, run
7. Start the test, after the effect