Set workspace location for RCP application

Veröffentlicht von

In my Eclipse / RCP application the .metadata directory was always created in the working directory. This worked fine when I was opening the application normally.

However, I needed file associations, so the user can just double click on file somewhere on his computer and open the file.

If you do this, the working directory is set to the directory where the file is located. This resulted in the creation of a .metadata directy at the same location. Brrr…

Since I dont like the creation of .metadata in the working directory either, because thats usually the application folder and not writeable, this needed to be addressed anyway.

So I looked for a solution to change the workspace location for the application.

To achieve this, two steps are neccessary. First we add an additional parameter in the Run configuration:

Working dir1

 

The paramater is -data @noDefault and makes it possible for us to set up our own location.

Which we do in the *Application class of our application:

Working dir2

 

Here is the example code for copy and paste:

try {
    Location instanceLoc = Platform.getInstanceLocation();

    // set location to c:\temp
    instanceLoc.set(new URL("file", null, "c:\\temp"), false);
}
catch (Exception err) {
    System.out.println(err.getMessage());
}

In the example we just use c:\temp, but you usually might want to set this path to the application data folder on the system.

Kommentar hinterlassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert