Setting the working directory for an eclipse plug-in

In the Eclipse plugin I am developing, I am querying some Prolog files that are in my development directory. In addition, an initialization file located at the root of my working directory is automatically loaded by the Prolog engine I am using. All these files are resources of my plugin.

When executing my application as a java standalone the only thing I need to do is to set, in the Eclipse Run Configurations dialog, the working directory to my default output directory. Then when executing my application the Prolog engine starts at the directory where the initialization file is located, and it is able to locate and load the prolog files of the application when needed. This Prolog engine is started from Java using the JPL library.

My problem started when I wanted to build an Eclipse plug-in of my application. Apparently the default working directory for plugins cannot be changed in the Run Configurations dialog (at least that is the case in my Mac setting), otherwise an infinite list of exceptions appear when the plug-in is executed. So what I would like to know is if there is another way to setup the working directory for a plugin, both during the development lifecycle (i.e., when I launch my plugin as an Eclipse Application) and in production (i.e., when the plugin is in the plugin directory).

Thanks !!


Working directory is set for the application not a plugin. I can imagine the mess if all plugins would try to set the working directory to their liking...

Files in a plugin can be found using the Bundle class which can be accessed using plugin activator. This will give you a URL that most likely points to a JAR entry. FileLocator class can be used to "convert" that URL to a file URL (file will be extracted from JAR).

URL url = Activator.getDefault().getBundle().getEntry("file path in JAR");
URL fileUrl = FileLocator.toFileURL(url);
File file = new File(url.getPath());

If the file MUST be in the working directory then you can copy it there.

Need Your Help

How to improve accuracy of indoor positioning?

wifi trilateration indoor-positioning-system

I should be developing an indoor positioning system for some place , so I started by gathering info about how to develop such a system , the question I am up to now is : what controls the accuracy of

How to change background color of an eps file while converting it to jpeg or png

image-manipulation ghostscript eps image-conversion

I am converting eps (Encapsulated PostScript) files to jpeg files with ghostscript. A sample command I use is:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.