You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@uima.apache.org by Tong Fin <to...@gmail.com> on 2010/04/24 17:47:33 UTC
Re: ResourceAccessException by using getResourceFilePath in Eclipse
Plug-In
Kai,
Is your plugin a compressed jar (like com.myconpany.myplugin.jar) or a
folder ?
If the plugin is a jar and you try to read a file from the path, it might
not work.
-- Tong
On Sat, Apr 24, 2010 at 6:56 AM, Kai Schlamp <sc...@gmx.de> wrote:
> Hello.
>
> I already asked a similiar question about a year ago. But I never solved
> that
> problem. Maybe there is a solution in the meantime or just did overlook
> something at that time.
>
> My UIMA analysis engine can also be run inside the Eclipse environment as
> an
> Eclipse Plug-in. The problem is that I have to get the absolute path of
> some
> resource (for an integrated third party library).
>
> This is works correctly, but I don't need a stream:
> getContext().getResourceAsStream("resource")
>
> But this doesn't work (throws an ResourceAccessException):
> getContext().getResourceFilePath("resource")
>
> And yes ... I already use: Eclipse-RegisterBuddy: org.apache.uima.runtime
> and "resource" is on the classpath (that is why the first method call
> works).
>
> Any suggestions?
>
> Regards,
> Kai
>
>
Re: ResourceAccessException by using getResourceFilePath in Eclipse Plug-In
Posted by Kai Schlamp <sc...@gmx.de>.
Hy Tong.
Yes, that is where the problem lies. When running an Eclipse plugin (or also
OSGi bundle) a call to
myObject.class.getClassLoader().getResource("sample.dat").toURI() does not
return the direct file path ("file:..."), but a bundle resource
("bundleresource:..."). There was once a bug report on Eclipse to change that,
but the report was declared as invalid
(https://bugs.eclipse.org/bugs/show_bug.cgi?id=65673). This is because it seems
that it is not specified by the Java platform that getResource must return a
"file" resource.
Re: ResourceAccessException by using getResourceFilePath in Eclipse
Plug-In
Posted by Tong Fin <to...@gmail.com>.
Kai,
The following source code expects to have "file" for the URI scheme:
public String getResourceFilePath(String aKey) throws
ResourceAccessException {
URI resourceUri = getResourceURI(aKey);
if (resourceUri != null) {
if ("file".equals(resourceUri.getScheme())) {
return resourceUri.getPath();
}
else {
throw new ResourceAccessException(); //TODO: error message
}
}
else {
return null;
}
}
You might try to add "file" to see if it works.
But, it might not what you would like to have.
-- Tong
On Sun, Apr 25, 2010 at 3:17 PM, Kai Schlamp <sc...@gmx.de> wrote:
> Something I forgot ... here is the full exception trace:
> http://pastebin.com/E0FUUKas
>
> Regards,
> Kai
>
>
>
>
Re: ResourceAccessException by using getResourceFilePath in Eclipse Plug-In
Posted by Kai Schlamp <sc...@gmx.de>.
Something I forgot ... here is the full exception trace:
http://pastebin.com/E0FUUKas
Regards,
Kai
Re: ResourceAccessException by using getResourceFilePath in Eclipse Plug-In
Posted by Kai Schlamp <sc...@gmx.de>.
Tong Fin <to...@...> writes:
> Kai,
> Here is another hint to try:
> Do you try to print to the console the full file path of "resource".
> It is possible that Eclipse tries to find the file in the "current
> directory" that is at somewhere that you never expect it to be.
No, I don't try to print anything to the console.
getContext().getResourceFilePath("resource") is enough to throw the exception.
I guess that it fails cause getResourceFilePath takes the classloader of the
below running Eclipse framework.
And that classloader only returns paths within
a bundle and not local file system paths.
To get local file system paths one has to use the FileLocator in Eclipse, but
that would make the analysis engine
Eclipse dependent.
Not sure if my guess is right as I am not an Eclipse expert.
But the result is that it makes it hard to write UIMA analysis engines as OSGi
bundles or Eclipse Plug-Ins that define resources the UIMA way.
Regards,
Kai
Re: ResourceAccessException by using getResourceFilePath in Eclipse
Plug-In
Posted by Tong Fin <to...@gmail.com>.
Kai,
Here is another hint to try:
Do you try to print to the console the full file path of "resource".
It is possible that Eclipse tries to find the file in the "current
directory" that is at somewhere that you never expect it to be.
-- Tong
On Sat, Apr 24, 2010 at 12:26 PM, Kai Schlamp <sc...@gmx.de> wrote:
> > Kai,
> > Is your plugin a compressed jar (like com.myconpany.myplugin.jar) or a
> > folder ?
> > If the plugin is a jar and you try to read a file from the path, it might
> > not work.
>
> Thanks for the hint, Tong. I run it directly from the Eclipse IDE. The
> resource
> file is in a resource folder. The resource folder is on the top level of
> the
> Plug-In project and added to the classpath. So it is a folder (and not
> packaged
> yet).
>
> I am looking for a way to design my UIMA Analysis Engines so that they run
> as
> part of Eclipse Plug-Ins (better to say as part of an Eclipse RCP
> application)
> and with non Eclipse UIMA applications.
> But those classpath things seems to make it quite hard when using external
> resources.
>
> Regards,
> Kai
>
>
>
>
>
Re: ResourceAccessException by using getResourceFilePath in Eclipse Plug-In
Posted by Kai Schlamp <sc...@gmx.de>.
> Kai,
> Is your plugin a compressed jar (like com.myconpany.myplugin.jar) or a
> folder ?
> If the plugin is a jar and you try to read a file from the path, it might
> not work.
Thanks for the hint, Tong. I run it directly from the Eclipse IDE. The resource
file is in a resource folder. The resource folder is on the top level of the
Plug-In project and added to the classpath. So it is a folder (and not packaged
yet).
I am looking for a way to design my UIMA Analysis Engines so that they run as
part of Eclipse Plug-Ins (better to say as part of an Eclipse RCP application)
and with non Eclipse UIMA applications.
But those classpath things seems to make it quite hard when using external
resources.
Regards,
Kai