uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marshall Schor <...@schor.com>
Subject Re: Making JAR files reading from within
Date Mon, 11 Aug 2008 19:38:20 GMT

Ahmed Abdeen Hamed wrote:
> Hi Hannes,Thank you for your response.
> I have configuration files, UIMA descriptors, models and dictionaries in my
> JAR. After I deployed, the JAR is not able to see those files inside itself
> and I get FIleNotFoundException when I run the JAR file the command line.
> This problem disappears entirely if I extract the JAR and the files are
> copied into the file system. My question is, how do I tell the JAR that
> those files are already inside it instead of extracting it? The suggestion
> you have given me is very handy in the case of reading a simple file
> contents. But if the JAR can't see the applications' descriptors then
> getting the contents as streams becomes very messy because those descriptors
> have references to other descriptors. So, I am not still sure how to tell
> the JAR to access all the descriptors as one problem I have with the JAR.
> Any other suggestions?
> Thanks again!
> Ahmed
Here are perhaps 2 solutions:

1) run a process that extracts the Jar contents into the file system, at 
a "well known" location (maybe a temp directory), before running the 
application :-)

2) I don't think there is a general solution for this.  For the 
particular case of reading the XML descriptors, where the descriptors 
might "import" other descriptors, this can be supported in Jar files by 
writing the Apache UIMA "import" elements using the "name=" attribute 
rather than the "location=" attribute.  When you use the name= 
attribute, the name is looked up in the current Java class path to 
locate the resource.  The name must not include the final ".xml" - that 
is appended automatically.  And you can specify which subdirectory in 
the JAR archive the file is located in, by prefixing name with the 
containing directories (if any) separated by the "period" character "." 
-- this is the same convention used by Java itself when locating classes 
within packages.

> On Mon, Aug 11, 2008 at 5:37 AM, Hannes Carl Meyer <
> hannescarl@googlemail.com> wrote:
>> Hi Ahmed,
>> yes it is possible to access files from inside the jar, but in which
>> context? In plain Java you can do something like this:
>> YourClass.class.getClassLoader().getResourceAsStream("yourpackage/resource");
>> Regards
>> Hannes
>> 2008/8/8 Ahmed Abdeen Hamed <ahmed.elmasri@gmail.com>
>>> Hello,Is there a way to tell a jar file to access its contents (txt and
>>> config) files instead of looking for such files on the filesystem? I
>>> created
>>> a UIMA-based application and it is successfully working from my machine
>>> using the command-line. However, if I put the jar on another machine it
>>> doesn't look inside itself to access model files for examples. I have
>> been
>>> looking into options and I found out that there is a way to access the
>>> jars's internals one file at a time, and read it contents online at at
>>> time.
>>> However, that makes me reinvent my application again to get it to
>>> manipulate
>>> the files from the jars even though my program has already done that. Is
>>> there a flag that you can turn on to tell the the jar to access its
>>> contents
>>> vs redoing this again programatically?
>>> Thank you for you help!
>>> -Ahmed

View raw message