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 How do I find out the install location of a plug-in?"

 
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
You should generally avoid making assumptions about the location of a plug-in
+
You should generally avoid making assumptions about the location of a plug-in at runtime.  To find resources, such as images, that are stored in your plug-in&#146;s install directory, you can use URLs provided by the <tt>Platform</tt> class. These URLs use a special Eclipse Platform protocol, but if you are using them only to read files, it does not matter.  
at runtime.  To find resources, such as images, that are stored in your plug-in&#146;s  
+
install directory, you can use URLs provided by the <tt>Platform</tt> class.
+
These URLs use a special Eclipse Platform protocol, but if you are
+
using them only to read files, it does not matter.  
+
  
 +
The following snippet  opens an input stream on a file called <tt>sample.gif</tt> located  in a subdirectory, called <tt>icons</tt>, of a plug-in&#146;s install directory:
  
 
 
The following snippet
 
opens an input stream on a file called <tt>sample.gif</tt> located
 
in a subdirectory, called <tt>icons</tt>, of a plug-in&#146;s install directory:
 
 
<pre>
 
<pre>
 
   Bundle bundle = Platform.getBundle(yourPluginId);
 
   Bundle bundle = Platform.getBundle(yourPluginId);
 
   Path path = new Path("icons/sample.gif");
 
   Path path = new Path("icons/sample.gif");
   URL fileURL = Platform.find(bundle, path);
+
   URL fileURL = FileLocator.find(bundle, path, null);
 
   InputStream in = fileURL.openStream();
 
   InputStream in = fileURL.openStream();
 
</pre>
 
</pre>
  
 
+
If you need to know the file system location of a plug-in, you need to use <tt>FileLocator.resolve(URL)</tt>.  This method converts a platform URL to a standard URL protocol, such as HyperText Transfer Protocol (HTTP), or file.  Note that the Eclipse Platform does not specify that plug-ins must exist in the local file system, so you cannot rely on this method&#146;s returning a file system URL under all circumstances in the future.
 
+
If you need to know the file system location of a plug-in, you need to  
+
use <tt>Platform.resolve(URL)</tt>.  This method converts a  
+
platform URL to a standard URL protocol, such as HyperText
+
Transfer Protocol (HTTP), or file.  Note  
+
that the Eclipse Platform does not specify that plug-ins  
+
must exist in the local file system, so you cannot rely on this
+
method&#146;s returning a file system URL under all circumstances in the future.
+
 
+
 
+
 
+
 
+
  
  
 
== See Also: ==
 
== See Also: ==
 +
*[[FAQ Where do plug-ins store their state?]]
  
 
+
{{Template:FAQ_Tagline}}
[[FAQ_Where_do_plug-ins_store_their_state%3F]]
+
 
+
<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 04:51, 26 February 2018

You should generally avoid making assumptions about the location of a plug-in at runtime. To find resources, such as images, that are stored in your plug-in&#146;s install directory, you can use URLs provided by the Platform class. These URLs use a special Eclipse Platform protocol, but if you are using them only to read files, it does not matter.

The following snippet opens an input stream on a file called sample.gif located in a subdirectory, called icons, of a plug-in&#146;s install directory:

   Bundle bundle = Platform.getBundle(yourPluginId);
   Path path = new Path("icons/sample.gif");
   URL fileURL = FileLocator.find(bundle, path, null);
   InputStream in = fileURL.openStream();

If you need to know the file system location of a plug-in, you need to use FileLocator.resolve(URL). This method converts a platform URL to a standard URL protocol, such as HyperText Transfer Protocol (HTTP), or file. Note that the Eclipse Platform does not specify that plug-ins must exist in the local file system, so you cannot rely on this method&#146;s returning a file system URL under all circumstances in the future.


See Also:


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.

Back to the top