当前位置

首页 > IT科技 > plug-in - java

plug-in - java

推荐人: 来源: 秒知社 阅读: 1.73W 次

<link rel="stylesheet" href="https://js.how234.com/third-party/SyntaxHighlighter/shCoreDefault.css" type="text/css" /><script type="text/javascript" src="https://js.how234.com/third-party/SyntaxHighlighter/shCore.js"></script><script type="text/javascript"> SyntaxHighlighter.all(); </script>

java plug-in是什么,让我们一起了解一下?

Plugin是一种计算机应用程序,它和主应用程序(host application)互相交互,以提供特定的功能,使得在浏览器中运行Java程序成为可能,Java Plug-in在浏览器中作为插件存在,同时也扩展了浏览器的功能。

我们使用Java Plug-in,可以通过在html页面中嵌入

如何使用

将applet嵌入到网页中,最早的使用方法就是使用

注意:Sun推荐在企业内部网(Intranet)中,推荐使用

java plug-in

plug-in的实现机制是什么?

1、主应用程序提供给插件可以使用的服务,让插件在主应用程序中注册插件本身,以及和插件进行数据交换的协议。插件依赖于主应用程序提供的这些服务,通常不能独立运行。相反地,主应用程序和插件是分离的,这就使得我们可以不改变主应用程序而动态增加或更新插件。

2、公开的应用程序接口(API)提供一个标准接口,允许第三方编写插件和主应用程序交互。一个稳定的API必须在主应用程序版本升级后第三方插件仍可以运行。插件同时也延长了过时的应用程序的生命。Adobe Photoshop 和 After Effects 提供给插件的API已经成为一种图像处理软件API的标准,被相类的图像处理软件所采纳。其它类似的API包括 Audio Units 和VST。

3、这种插件的机制很普遍,比如一个网络交换器,它有一个没被占用而且是非标准的端口,用它来接纳不同的任意的物理层连接;再比如计算机硬件制造业的行业标准架构(Industry Standard Architecture)和IBM著名的微通道架构(Micro Channel Architecture),都允许第三方设备。这些都是类似插件的一种机制。

实战操作,具体代码如下:

Activator类被默认实现,继承AbstractUIPlugin。其中start()和stop()方法,分别会在启动和停止时调用。

public class Activator extends AbstractUIPlugin {    // The plug-in ID    public static final String PLUGIN_ID = "com.plugin.blog.demo"; //$NON-NLS-1$    // The shared instance    private static Activator plugin;    /**     * The constructor     */    public Activator() {    }    /*     * (non-Javadoc)     * @see org.eclipse.ui.plugin.AbstractUIPlugin#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)     */    public 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;    }}