TestParser Fails to Find config.xml

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

TestParser Fails to Find config.xml

Keith R. Bennett
I'm getting an error when running the TestParsers test.  The test appears to look for the XML configuration file in the first directory in the class path, which, in my case, is in the Java home directory tree:

/System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/config/config.xml

TestParsers.setUp() contains the following code:

----
String sep = File.separator;
StringTokenizer st = new StringTokenizer(System.getProperty(
        "java.class.path"), File.pathSeparator);

classDir = new File(st.nextToken());

config = classDir.getParent() + sep + "config" + sep + "config.xml";
----

Is there another way we can specify the location of the config.xml file that would be more reliable?  Maybe by the following?:

URL configUrl = this.getClass().getResource("/config.xml");

I noticed there is already a config.xml in src/main/resources, which is where it should be for the getResource() call above to work.

Then, we'd also need to change:

LiusConfig getInstance(String configFile)
to
LiusConfig getInstance(URL configUrl)

- Keith
Reply | Threaded
Open this post in threaded view
|

Re: TestParser Fails to Find config.xml

Sami Siren-2
kbennett wrote:

> I'm getting an error when running the TestParsers test.  The test appears to
> look for the XML configuration file in the first directory in the class
> path, which, in my case, is in the Java home directory tree:
>
> /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/config/config.xml
>
> TestParsers.setUp() contains the following code:
>
> ----
> String sep = File.separator;
> StringTokenizer st = new StringTokenizer(System.getProperty(
>         "java.class.path"), File.pathSeparator);
>
> classDir = new File(st.nextToken());
>
> config = classDir.getParent() + sep + "config" + sep + "config.xml";
> ----

I noticed this too, that is why I didn't attack tika-11.

> Is there another way we can specify the location of the config.xml file that
> would be more reliable?  Maybe by the following?:
>
> URL configUrl = this.getClass().getResource("/config.xml");
>
> I noticed there is already a config.xml in src/main/resources, which is
> where it should be for the getResource() call above to work.
>
> Then, we'd also need to change:
>
> LiusConfig getInstance(String configFile)
> to
> LiusConfig getInstance(URL configUrl)

This sounds like a good direction to me, I would however use a context
classloader to find the resource and not a static one.

--
 Sami Siren


Reply | Threaded
Open this post in threaded view
|

Re: TestParser Fails to Find config.xml

Rida Benjelloun
+1

On 9/12/07, Sami Siren <[hidden email]> wrote:

>
> kbennett wrote:
> > I'm getting an error when running the TestParsers test.  The test
> appears to
> > look for the XML configuration file in the first directory in the class
> > path, which, in my case, is in the Java home directory tree:
> >
> >
> /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home/lib/config/config.xml
> >
> > TestParsers.setUp() contains the following code:
> >
> > ----
> > String sep = File.separator;
> > StringTokenizer st = new StringTokenizer(System.getProperty(
> >         "java.class.path"), File.pathSeparator);
> >
> > classDir = new File(st.nextToken());
> >
> > config = classDir.getParent() + sep + "config" + sep + "config.xml";
> > ----
>
> I noticed this too, that is why I didn't attack tika-11.
>
> > Is there another way we can specify the location of the config.xml file
> that
> > would be more reliable?  Maybe by the following?:
> >
> > URL configUrl = this.getClass().getResource("/config.xml");
> >
> > I noticed there is already a config.xml in src/main/resources, which is
> > where it should be for the getResource() call above to work.
> >
> > Then, we'd also need to change:
> >
> > LiusConfig getInstance(String configFile)
> > to
> > LiusConfig getInstance(URL configUrl)
>
> This sounds like a good direction to me, I would however use a context
> classloader to find the resource and not a static one.
>
> --
> Sami Siren
>
>
>


--
---------------------------------------------------------
Rida Benjelloun
Doculibre inc.
[hidden email]
[hidden email]
Cel: 418-262-3222
Tel: 418-353-3390
Site Web : http://www.doculibre.com
---------------------------------------------------------
Reply | Threaded
Open this post in threaded view
|

Re: TestParser Fails to Find config.xml

Keith R. Bennett
In reply to this post by Sami Siren-2
Do you all have any opinions about which class loader to use to load the tika-config.xml file?  I used the one I was more familiar with, but Sami brought up a question about it (see below).  Someone else I spoke with suggested using both classloaders (try #1, if it fails, try #2).

- Keith

Sami Siren-2 wrote
kbennett wrote:

> Is there another way we can specify the location of the config.xml file that
> would be more reliable?  Maybe by the following?:
>
> URL configUrl = this.getClass().getResource("/config.xml");

This sounds like a good direction to me, I would however use a context
classloader to find the resource and not a static one.
Reply | Threaded
Open this post in threaded view
|

Re: TestParser Fails to Find config.xml

robert burrell donkin-2
On 10/12/07, Keith R. Bennett <[hidden email]> wrote:
>
> Do you all have any opinions about which class loader to use to load the
> tika-config.xml file?  I used the one I was more familiar with, but Sami
> brought up a question about it (see below).  Someone else I spoke with
> suggested using both classloaders (try #1, if it fails, try #2).

trying the context classloader and then falling back to the class
classloader is the best approach

- robert
Reply | Threaded
Open this post in threaded view
|

Re: TestParser Fails to Find config.xml

Jukka Zitting
Hi,

On 10/13/07, Robert Burrell Donkin <[hidden email]> wrote:
> On 10/12/07, Keith R. Bennett <[hidden email]> wrote:
> > Do you all have any opinions about which class loader to use to load the
> > tika-config.xml file?  I used the one I was more familiar with, but Sami
> > brought up a question about it (see below).  Someone else I spoke with
> > suggested using both classloaders (try #1, if it fails, try #2).
>
> trying the context classloader and then falling back to the class
> classloader is the best approach

IMHO this should be a client concern. Tika itself should only take an
InputStream and not care where the configuration stream is coming
from. I'm OK with the current utility methods that take a filename, a
File, or a URL instead, but playing with classloaders is a sure sign
of trouble.

The original issue about TestParsers.java is easily solved, see
TIKA-62 and revision 584386.

BR,

Jukka Zitting
Reply | Threaded
Open this post in threaded view
|

Re: TestParser Fails to Find config.xml

robert burrell donkin-2
On 10/13/07, Jukka Zitting <[hidden email]> wrote:

> Hi,
>
> On 10/13/07, Robert Burrell Donkin <[hidden email]> wrote:
> > On 10/12/07, Keith R. Bennett <[hidden email]> wrote:
> > > Do you all have any opinions about which class loader to use to load the
> > > tika-config.xml file?  I used the one I was more familiar with, but Sami
> > > brought up a question about it (see below).  Someone else I spoke with
> > > suggested using both classloaders (try #1, if it fails, try #2).
> >
> > trying the context classloader and then falling back to the class
> > classloader is the best approach
>
> IMHO this should be a client concern. Tika itself should only take an
> InputStream and not care where the configuration stream is coming
> from. I'm OK with the current utility methods that take a filename, a
> File, or a URL instead, but playing with classloaders is a sure sign
> of trouble.

+1

- robert