插件和外部jar文件之间的区别

时间:2013-10-24 19:46:32

标签: plugins eclipse-plugin

在java的上下文中,“插件”和“外部jar /第三方库/外部依赖性等”之间是否存在概念上的差异?

这个问题的必然结果是:当你在eclipse中下载并“安装”一个插件时,除了在.plugin目录中复制一个jar之外,它还会做什么吗?

1 个答案:

答案 0 :(得分:1)

Eclipse插件必须包含MANIFEST.MF中的许多条目才能被识别为插件。这些提供了插件的名称和版本,以及所需的其他插件列表和许多其他值。

该插件还可能包含plugin.xml,它定义了插件使用的Eclipse扩展点,并且还可以声明新的扩展点。

Eclipse插件不必是jar文件,也可以使用等效的目录结构。

当Eclipse安装插件时,它会从MANIFEST.MF和plugin.xml中获取信息来更新内部表,例如扩展点贡献,每个插件的类路径等等。

示例plugin.xml,它声明了一个新的扩展点并使用现有的扩展点:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension-point id="editor" name="%extension-point.name" schema="schema/editor.exsd"/>
   <extension
         id="coreFragment"
         point="org.eclipse.e4.workbench.model">
      <fragment
            uri="fragment.e4xmi">
      </fragment>
   </extension>
</plugin>

示例MANIFEST.MF

Manifest-Version: 1.0
Export-Package: greg.music.core.common,greg.music.core.e4util,greg.mus
 ic.core.editor,greg.music.core.preferences,greg.music.core.progress,g
 reg.music.core.services,greg.music.core.showin,greg.music.core.util,g
 reg.music.core.views,greg.music.core.xml
Service-Component: OSGI-INF/playerStateService.xml,OSGI-INF/preference
 Settings.xml,OSGI-INF/extensionFactory.xml
Bundle-ActivationPolicy: lazy
Bundle-Name: %Bundle-Name
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.core.runtime,greg.music.forms;bundle-versi
 on="1.0.0",greg.music.parts;bundle-version="1.0.0",greg.music.annotat
 ions;bundle-version="1.0.0",javazoom.jlgui.basicplayer;bundle-version
 ="1.6.0",org.eclipse.jface;bundle-version="3.8.101",org.eclipse.e4.co
 re.contexts;bundle-version="1.1.0",org.eclipse.e4.core.commands;bundl
 e-version="0.10.1",org.eclipse.e4.core.di;bundle-version="1.1.0",org.
 eclipse.e4.core.services;bundle-version="1.0.0",org.eclipse.e4.ui.mod
 el.workbench;bundle-version="0.10.1",org.eclipse.e4.ui.workbench;bund
 le-version="0.11.0",org.eclipse.e4.ui.services;bundle-version="0.10.3
 ",com.ibm.icu;bundle-version="4.4.2",org.eclipse.emf.common;bundle-ve
 rsion="2.9.0",org.eclipse.emf.ecore;bundle-version="2.9.0",org.eclips
 e.e4.ui.css.swt.theme;bundle-version="0.9.100",org.eclipse.e4.ui.di;b
 undle-version="1.0.0",org.joda.time;bundle-version="2.3.0",com.google
 .guava;bundle-version="14.0.1"
Bundle-Vendor: %Bundle-Vendor
Bundle-Version: 1.0.0.201310241930
Bundle-ManifestVersion: 2
Bundle-Activator: greg.music.core.Activator
Import-Package: javax.annotation;version="1.0.0",javax.inject;version=
 "1.0.0"
Bundle-SymbolicName: greg.music.core;singleton:=true