Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "FAQ What is a plug-in fragment?"

m (Change � to ')
 
(3 intermediate revisions by 3 users not shown)
Line 3: Line 3:
 
the rest of the plug-in.  For example,
 
the rest of the plug-in.  For example,
 
a plug-in may have a library that is specific to a particular operating system or
 
a plug-in may have a library that is specific to a particular operating system or
windowing system or a language pack that adds translations for the plug-in’s
+
windowing system or a language pack that adds translations for the plug-in's
 
messages. In these situations, you can create a fragment that is associated
 
messages. In these situations, you can create a fragment that is associated
 
with a particular host plug-in.  On disk, a fragment looks  
 
with a particular host plug-in.  On disk, a fragment looks  
Line 9: Line 9:
 
cosmetic differences.
 
cosmetic differences.
  
* The manifest is stored in a file called <tt>fragment.xml</tt> instead of <tt>plugin.xml</tt>.</li>
+
* The manifest is stored in a file called <tt>fragment.xml</tt> instead of <tt>plugin.xml</tt>.
* The top-level element in the manifest is called <tt>fragment</tt> and has two extra attributes&#151;<tt>plugin-id</tt> and  
+
* The top-level element in the manifest is called <tt>fragment</tt> and has two extra attributes, <tt>plugin-id</tt> and <tt>plugin-version</tt>, for specifying the ID and version number of the host plug-in.
<tt>plugin-version</tt>&#151;for specifying the ID and version number of the host plug-in.
+
</li>
+
 
* The fragment manifest does not need its own <tt>requires</tt> element. The fragment will automatically inherit the <tt>requires</tt> element of its host plug-in. It can add <tt>requires</tt> elements if it needs access to plug-ins that are not required by the host plug-in.
 
* The fragment manifest does not need its own <tt>requires</tt> element. The fragment will automatically inherit the <tt>requires</tt> element of its host plug-in. It can add <tt>requires</tt> elements if it needs access to plug-ins that are not required by the host plug-in.
  
Line 19: Line 17:
 
When it is loaded by the platform loader, a fragment  
 
When it is loaded by the platform loader, a fragment  
 
is logically, but not physically, merged into the host plug-in.
 
is logically, but not physically, merged into the host plug-in.
The end result is exactly the same as if the fragment&#146;s manifest were copied
+
The end result is exactly the same as if the fragment's manifest were copied
 
into the plug-in manifest, and all the files in the fragment directory appear
 
into the plug-in manifest, and all the files in the fragment directory appear
as if they were located in the plug-in&#146;s install directory. Thus, a runtime library
+
as if they were located in the plug-in's install directory. Thus, a runtime library
 
supplied by a fragment appears on the classpath of its host plug-in. In fact,
 
supplied by a fragment appears on the classpath of its host plug-in. In fact,
 
a Java class in a fragment can be in the same package as a class in the host
 
a Java class in a fragment can be in the same package as a class in the host
 
and will even have access to package-visible methods on the  
 
and will even have access to package-visible methods on the  
host&#146;s classes.
+
host's classes.
 
The methods <tt>find</tt> and <tt>openStream</tt> on  
 
The methods <tt>find</tt> and <tt>openStream</tt> on  
 
<tt>Plugin</tt>, which take as a  
 
<tt>Plugin</tt>, which take as a  
parameter a path relative to the plug-in&#146;s install directory, can be used to  
+
parameter a path relative to the plug-in's install directory, can be used to  
 
locate and read resources stored in the fragment install directory.
 
locate and read resources stored in the fragment install directory.
  
Line 39: Line 37:
  
  
[[FAQ_What_is_a_plug-in%3F]]
+
[[FAQ What is a plug-in?]]
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 12:39, 26 May 2017

Sometimes it is useful to make part of a plug-in optional, allowing it to be installed, uninstalled, or updated independently from the rest of the plug-in. For example, a plug-in may have a library that is specific to a particular operating system or windowing system or a language pack that adds translations for the plug-in's messages. In these situations, you can create a fragment that is associated with a particular host plug-in. On disk, a fragment looks almost exactly the same as a plug-in, except for a few cosmetic differences.

  • The manifest is stored in a file called fragment.xml instead of plugin.xml.
  • The top-level element in the manifest is called fragment and has two extra attributes, plugin-id and plugin-version, for specifying the ID and version number of the host plug-in.
  • The fragment manifest does not need its own requires element. The fragment will automatically inherit the requires element of its host plug-in. It can add requires elements if it needs access to plug-ins that are not required by the host plug-in.

Apart from these differences, a fragment appears much the same as a normal plug-in. A fragment can specify libraries, extensions, and other files. When it is loaded by the platform loader, a fragment is logically, but not physically, merged into the host plug-in. The end result is exactly the same as if the fragment's manifest were copied into the plug-in manifest, and all the files in the fragment directory appear as if they were located in the plug-in's install directory. Thus, a runtime library supplied by a fragment appears on the classpath of its host plug-in. In fact, a Java class in a fragment can be in the same package as a class in the host and will even have access to package-visible methods on the host's classes. The methods find and openStream on Plugin, which take as a parameter a path relative to the plug-in's install directory, can be used to locate and read resources stored in the fragment install directory.




See Also:

FAQ What is a plug-in?


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.

Copyright © Eclipse Foundation, Inc. All Rights Reserved.