You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@opennlp.apache.org by Stephan Greene <sg...@coderyte.com> on 2012/04/18 17:59:15 UTC

model version issues outside eclipse

I'm using OpenNLP 1.5.2-snapshot with the UIMA wrappers. When I run OpenNLP inside eclipse, the tokenizer and sentence detector can read their respective 1.5.0 models with no problem and everything works. If I try to invoke something on the command line, it fails to find the version resource file opennlp/tools/util/opennlp.version, defaults back to the dev version 0.0.0-SNAPSHOT, then fails to load the model, claiming a version incompatibility. The version resource file is right there in the OpenNLP jar file.

I'm running Java 1.6 on Mac OSX Lion. Does anyone know why this would differ inside and outside eclipse, and how to fix it? Presumably something to do with resource loading. 

Line 192 of Version.java sets versionIn to null.

    InputStream versionIn = Version.class.getResourceAsStream("opennlp.version");

Thanks.

Stephan


Re: model version issues outside eclipse

Posted by Stephan Greene <sg...@coderyte.com>.
On Apr 19, 2012, at 3:33 AM, Jörn Kottmann wrote:

> I still don't get it. We do:
> Version.class.getResourceAsStream("opennlp.version");
> 
> This call uses the classloader which loaded the Version class to look for the opennlp.version
> file in the same package. How can that fail if the file is there?

Right, I don't have a good explanation. Somehow restricting the classpath is a workaround, but the faulty behavior is really unexplained.


Re: model version issues outside eclipse

Posted by Jörn Kottmann <ko...@gmail.com>.
On 04/18/2012 08:06 PM, Stephan Greene wrote:
> On Apr 18, 2012, at 1:21 PM, Jörn Kottmann wrote:
>
>> Its strange that it cannot load it. Based on your other post you could assume that it
>> has to do with your classpath. Do you use a different opennlp-tools.jar file?
>>
>> Or is something wrong with the line which tries to retrieve the version file?
> I have the same jar files across both methods of invocation so it's not the classpath. But your question about the getResourceAsStream() line got me thinking. I researched it a bit, and found that the behavior of this method will vary depending on what ClassLoader is active in the current context. Which ClassLoader you get is in turn affected by any number of things, including third party libraries and eclipse plugins.
>
> If I restrict my command line classpath specification explicitly to the minimal set of UIMA and OpenNLP jars that I need, it runs fine. I had been using wildcard syntax. I'm not sure how unreferenced libs could affect the ClassLoader, however. So, not the most satisfying resolution, but a resolution nonetheless. Given the nature of the issue, I would have expected the eclipse context to exhibit the problem, not the command line, though perhaps eclipse takes extra care in ClassLoader management.

I still don't get it. We do:
Version.class.getResourceAsStream("opennlp.version");

This call uses the classloader which loaded the Version class to look 
for the opennlp.version
file in the same package. How can that fail if the file is there?

Jörn


Re: model version issues outside eclipse

Posted by Stephan Greene <sg...@coderyte.com>.
On Apr 18, 2012, at 1:21 PM, Jörn Kottmann wrote:

> Its strange that it cannot load it. Based on your other post you could assume that it
> has to do with your classpath. Do you use a different opennlp-tools.jar file?
> 
> Or is something wrong with the line which tries to retrieve the version file?

I have the same jar files across both methods of invocation so it's not the classpath. But your question about the getResourceAsStream() line got me thinking. I researched it a bit, and found that the behavior of this method will vary depending on what ClassLoader is active in the current context. Which ClassLoader you get is in turn affected by any number of things, including third party libraries and eclipse plugins.

If I restrict my command line classpath specification explicitly to the minimal set of UIMA and OpenNLP jars that I need, it runs fine. I had been using wildcard syntax. I'm not sure how unreferenced libs could affect the ClassLoader, however. So, not the most satisfying resolution, but a resolution nonetheless. Given the nature of the issue, I would have expected the eclipse context to exhibit the problem, not the command line, though perhaps eclipse takes extra care in ClassLoader management.

Thanks, Jörn.

Re: model version issues outside eclipse

Posted by Jörn Kottmann <ko...@gmail.com>.
On 04/18/2012 06:30 PM, Stephan Greene wrote:
> I'm actually just invoking java directly on the command line. Something like:
>
> java -cp<path to UIMA and OPENNLP jars>  MainClass
>
> The main class is a UIMA utility that invokes a UIMA collection processing engine, which includes OpenNLP annotators within it.

Its strange that it cannot load it. Based on your other post you could 
assume that it
has to do with your classpath. Do you use a different opennlp-tools.jar 
file?

Or is something wrong with the line which tries to retrieve the version 
file?

Jörn

Re: model version issues outside eclipse

Posted by Stephan Greene <sg...@coderyte.com>.
I should add that if I set up the same java command as a Run Configuration within eclipse, it works fine. It's the same command except I don't put the classpath in the command line. It uses my dev project classpath, which points to the same jar files.

On Apr 18, 2012, at 12:30 PM, Stephan Greene wrote:

> I'm actually just invoking java directly on the command line. Something like:
> 
> java -cp <path to UIMA and OPENNLP jars> MainClass
> 
> The main class is a UIMA utility that invokes a UIMA collection processing engine, which includes OpenNLP annotators within it.
> 
> On Apr 18, 2012, at 12:17 PM, Jörn Kottmann wrote:
> 
>> On 04/18/2012 05:59 PM, Stephan Greene wrote:
>>> I'm running Java 1.6 on Mac OSX Lion. Does anyone know why this would differ inside and outside eclipse, and how to fix it? Presumably something to do with resource loading.
>>> 
>>> Line 192 of Version.java sets versionIn to null.
>>> 
>>>    InputStream versionIn = Version.class.getResourceAsStream("opennlp.version");
>> 
>> When exactly does this happen?
>> When you are running the bin/opennlp script inside opennlp-tools source folder?
>> 
>> This scripts uses maven to start the whole thing. Not to be confused with a second
>> script which is part of our binary distribution and does the same thing, but with starting
>> the jvm via java itself.
>> 
>> Jörn
> 


Re: model version issues outside eclipse

Posted by Stephan Greene <sg...@coderyte.com>.
I'm actually just invoking java directly on the command line. Something like:

java -cp <path to UIMA and OPENNLP jars> MainClass

The main class is a UIMA utility that invokes a UIMA collection processing engine, which includes OpenNLP annotators within it.

On Apr 18, 2012, at 12:17 PM, Jörn Kottmann wrote:

> On 04/18/2012 05:59 PM, Stephan Greene wrote:
>> I'm running Java 1.6 on Mac OSX Lion. Does anyone know why this would differ inside and outside eclipse, and how to fix it? Presumably something to do with resource loading.
>> 
>> Line 192 of Version.java sets versionIn to null.
>> 
>>     InputStream versionIn = Version.class.getResourceAsStream("opennlp.version");
> 
> When exactly does this happen?
> When you are running the bin/opennlp script inside opennlp-tools source folder?
> 
> This scripts uses maven to start the whole thing. Not to be confused with a second
> script which is part of our binary distribution and does the same thing, but with starting
> the jvm via java itself.
> 
> Jörn


Re: model version issues outside eclipse

Posted by Jörn Kottmann <ko...@gmail.com>.
On 04/18/2012 05:59 PM, Stephan Greene wrote:
> I'm running Java 1.6 on Mac OSX Lion. Does anyone know why this would differ inside and outside eclipse, and how to fix it? Presumably something to do with resource loading.
>
> Line 192 of Version.java sets versionIn to null.
>
>      InputStream versionIn = Version.class.getResourceAsStream("opennlp.version");

When exactly does this happen?
When you are running the bin/opennlp script inside opennlp-tools source 
folder?

This scripts uses maven to start the whole thing. Not to be confused 
with a second
script which is part of our binary distribution and does the same thing, 
but with starting
the jvm via java itself.

Jörn