Home » Eclipse Projects » Rich Client Platform (RCP) » Root directories, finding files
Root directories, finding files [message #453140] |
Sun, 23 July 2006 18:08 |
J. Michael Dean, M.D. Messages: 218 Registered: July 2009 |
Senior Member |
|
|
Continuing to struggle despite helpful comments. The scenario is that my
RCP must be able to open a text file called rules.clp, and this is a plain
text file. It is located in the "root" of my project, but I am unable to
figure out the path - this is still in the "Run as application" or "Run as
product" configuration. I have tried
Ipath path = Platform.getLocation().append("rules.clp");
File file = path.toFile();
This does not work when I try to open this with a FileReader:
java.io.FileNotFoundException:
/Users/mdean/Documents/runtime-EclipseApplication/rules.clp
(No such file or directory)
Cannot find the rules file.
And this indeed makes some sense because when I examine the runtime
directory there is no such file.
So I guess one question is how does Eclipse determine WHAT to move to the
runtime directory? I have checked that the file should be included in the
build.
When I export the application from the product export wizard, I have used
features as the basis, and in the build.properties have inserted a line that
does move the rules.clp file to the root of the exported application. The
file is then present at the exact same level as the app itself.
How do I access the root directory from the RCP when I have exported the
product? I would prefer to get the rules.clp file into the right place in
the first place, so that the application can be tested and run within the
Eclipse environment and exported as an RCP. But if I can at least access
the root directory from the RCP, I can get this kludged for the moment.
Thanks. I am sure that the answer will be extremely simple, but I am
approaching nearly two weeks of wrestling with this.
|
|
|
Re: Root directories, finding files [message #453142 is a reply to message #453140] |
Sun, 23 July 2006 21:49 |
Mario Winterer Messages: 136 Registered: July 2009 |
Senior Member |
|
|
J Michael Dean schrieb:
> Continuing to struggle despite helpful comments. The scenario is that my
> RCP must be able to open a text file called rules.clp, and this is a plain
> text file. It is located in the "root" of my project, but I am unable to
> figure out the path - this is still in the "Run as application" or "Run as
> product" configuration. I have tried
>
> Ipath path = Platform.getLocation().append("rules.clp");
> File file = path.toFile();
>
> This does not work when I try to open this with a FileReader:
>
> java.io.FileNotFoundException:
> /Users/mdean/Documents/runtime-EclipseApplication/rules.clp
> (No such file or directory)
>
> Cannot find the rules file.
>
> And this indeed makes some sense because when I examine the runtime
> directory there is no such file.
>
> So I guess one question is how does Eclipse determine WHAT to move to the
> runtime directory? I have checked that the file should be included in the
> build.
>
> When I export the application from the product export wizard, I have used
> features as the basis, and in the build.properties have inserted a line that
> does move the rules.clp file to the root of the exported application. The
> file is then present at the exact same level as the app itself.
>
> How do I access the root directory from the RCP when I have exported the
> product? I would prefer to get the rules.clp file into the right place in
> the first place, so that the application can be tested and run within the
> Eclipse environment and exported as an RCP. But if I can at least access
> the root directory from the RCP, I can get this kludged for the moment.
>
> Thanks. I am sure that the answer will be extremely simple, but I am
> approaching nearly two weeks of wrestling with this.
>
Hi Michael!
Platform.getLocation() returns the location of your application's working directory.
But if I don't misunderstand, your file is located in the root directory of your plugin.
(in eclipse-terms: <eclipse-install-dir>/plugins/<your-plugin-id>/rules.clp or
<eclipse-install-dir>/plugins/<your-plugin-id>.jar!rules.clp)
Please note that this location is read-only (especially if your plugin is exported as jar file).
To access rules.clp use one of the following methods:
1) Since eclipse 3.2:
InputStream input = FileLocator.openStream(MyPlugin.getDefault().getBundle(), new Path("rules.clp"), false);
try {
// read from stream
} finally {
input.close();
}
2) before eclipse 3.2 (deprecated, but working in 3.2):
InputStream input = MyPlugin.getDefault().openStream(new Path("rules.clp"));
// same as above
As you can see, both methods just return an InputStream, so modifications of rules.clp are not possible.
Best regards,
Tex
|
|
|
Re: Root directories, finding files [message #453143 is a reply to message #453140] |
Sun, 23 July 2006 21:52 |
Wayne Beaton Messages: 554 Registered: December 2017 |
Senior Member |
|
|
J Michael Dean wrote:
> Continuing to struggle despite helpful comments. The scenario is that my
> RCP must be able to open a text file called rules.clp, and this is a plain
> text file. It is located in the "root" of my project, but I am unable to
> figure out the path - this is still in the "Run as application" or "Run as
> product" configuration. I have tried
>
> Ipath path = Platform.getLocation().append("rules.clp");
> File file = path.toFile();
>
> This does not work when I try to open this with a FileReader:
>
> java.io.FileNotFoundException:
> /Users/mdean/Documents/runtime-EclipseApplication/rules.clp
> (No such file or directory)
>
> Cannot find the rules file.
>
> And this indeed makes some sense because when I examine the runtime
> directory there is no such file.
>
> So I guess one question is how does Eclipse determine WHAT to move to the
> runtime directory? I have checked that the file should be included in the
> build.
>
> When I export the application from the product export wizard, I have used
> features as the basis, and in the build.properties have inserted a line that
> does move the rules.clp file to the root of the exported application. The
> file is then present at the exact same level as the app itself.
>
> How do I access the root directory from the RCP when I have exported the
> product? I would prefer to get the rules.clp file into the right place in
> the first place, so that the application can be tested and run within the
> Eclipse environment and exported as an RCP. But if I can at least access
> the root directory from the RCP, I can get this kludged for the moment.
>
> Thanks. I am sure that the answer will be extremely simple, but I am
> approaching nearly two weeks of wrestling with this.
>
Assuming that the file you're looking for is in the root of your bundle,
and that you have an activator named "Activator", you can get a handle
on it using code like:
Activator.getDefault().getBundle().getResource("rules.clp");
Wayne
|
|
|
Re: Root directories, finding files [message #453148 is a reply to message #453142] |
Mon, 24 July 2006 02:51 |
J. Michael Dean, M.D. Messages: 218 Registered: July 2009 |
Senior Member |
|
|
Is there a way to land my rules.clp in the application's working directory?
That is probably what I really want to do, but not clear how to do that.
Thanks for previous suggestions.
On 7/23/06 3:49 PM, in article ea0qt9$ukk$1@utils.eclipse.org, "Mario
Winterer" <mario.winterer@gmx.at> wrote:
> J Michael Dean schrieb:
>> Continuing to struggle despite helpful comments. The scenario is that my
>> RCP must be able to open a text file called rules.clp, and this is a plain
>> text file. It is located in the "root" of my project, but I am unable to
>> figure out the path - this is still in the "Run as application" or "Run as
>> product" configuration. I have tried
>>
>> Ipath path = Platform.getLocation().append("rules.clp");
>> File file = path.toFile();
>>
>> This does not work when I try to open this with a FileReader:
>>
>> java.io.FileNotFoundException:
>> /Users/mdean/Documents/runtime-EclipseApplication/rules.clp
>> (No such file or directory)
>>
>> Cannot find the rules file.
>>
>> And this indeed makes some sense because when I examine the runtime
>> directory there is no such file.
>>
>> So I guess one question is how does Eclipse determine WHAT to move to the
>> runtime directory? I have checked that the file should be included in the
>> build.
>>
>> When I export the application from the product export wizard, I have used
>> features as the basis, and in the build.properties have inserted a line that
>> does move the rules.clp file to the root of the exported application. The
>> file is then present at the exact same level as the app itself.
>>
>> How do I access the root directory from the RCP when I have exported the
>> product? I would prefer to get the rules.clp file into the right place in
>> the first place, so that the application can be tested and run within the
>> Eclipse environment and exported as an RCP. But if I can at least access
>> the root directory from the RCP, I can get this kludged for the moment.
>>
>> Thanks. I am sure that the answer will be extremely simple, but I am
>> approaching nearly two weeks of wrestling with this.
>>
>
> Hi Michael!
>
> Platform.getLocation() returns the location of your application's working
> directory.
> But if I don't misunderstand, your file is located in the root directory of
> your plugin.
> (in eclipse-terms: <eclipse-install-dir>/plugins/<your-plugin-id>/rules.clp or
> <eclipse-install-dir>/plugins/<your-plugin-id>.jar!rules.clp)
>
> Please note that this location is read-only (especially if your plugin is
> exported as jar file).
>
> To access rules.clp use one of the following methods:
>
> 1) Since eclipse 3.2:
> InputStream input = FileLocator.openStream(MyPlugin.getDefault().getBundle(),
> new Path("rules.clp"), false);
> try {
> // read from stream
> } finally {
> input.close();
> }
>
> 2) before eclipse 3.2 (deprecated, but working in 3.2):
> InputStream input = MyPlugin.getDefault().openStream(new Path("rules.clp"));
> // same as above
>
> As you can see, both methods just return an InputStream, so modifications of
> rules.clp are not possible.
>
> Best regards,
> Tex
|
|
| |
Re: Root directories, finding files [message #453516 is a reply to message #453427] |
Tue, 01 August 2006 14:03 |
J. Michael Dean, M.D. Messages: 218 Registered: July 2009 |
Senior Member |
|
|
Thanks. The file is a complicated configuration file. For right now, I
have bundled it in the plugin - my earlier problems with this related to
trying to find the file before my bundle was finished starting, and this is
resolved.
However, I want to have two kinds of users - one kind of user won't even
know the file exists, but the other kind of user should be able to edit the
file as a text file. But there won't exactly be a "project folder" inside
this RCP, etc. Ideally, this super user could actually drag a different
configuration file into the installation and replace the old one, etc.
Does this make any sense? Thanks.
On 7/31/06 2:35 AM, in article eakfbr$ba2$1@utils.eclipse.org, "Mario
Winterer" <mario.winterer@gmx.at> wrote:
> J Michael Dean schrieb:
>> Is there a way to land my rules.clp in the application's working directory?
>> That is probably what I really want to do, but not clear how to do that.
>> Thanks for previous suggestions.
>>
>
> Do you mean "workspace" or really the application's working directory
> (in case of eclipse: the directory, where eclipse.exe can be found)?
>
> I don't think, any application-specific file should be in the working
> directory!
> Think about the following two rules:
> 1) If the file cannot be modified by your application it should be bundled
> with your plugin
> 2) If the file can be modified by your application (e.g. via preferences
> dialog),
> copy it to your plugin's storage location.
> 3) If the file can be modified by the user (e.g. via double-clicking it in the
> resource navigator),
> it must be somewhere in the workspace below a project folder.
>
> I think there is hardly any case where the file should be somewhere else.
> (Maybe your appliation is such a case, but that's on you to decide).
>
> Best regards,
> Tex
|
|
|
Goto Forum:
Current Time: Wed Oct 09 04:19:05 GMT 2024
Powered by FUDForum. Page generated in 0.04532 seconds
|