You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Bill Janssen <ja...@parc.com> on 2005/01/17 19:25:08 UTC

How to add a Lucene index to a jar file?

Hi.

I'd like to package up a Lucene index with the Lucene class files and
my own application classes into a single jar file, so that it forms a
"double-clickable" single-file Java application that supports
searching over the index.  However, I'm not sure how to read the index
(create an IndexReader) if the files that form the index are packaged
into the same jar file with the code.

If anyone could shed some light on how to do this, I'd appreciate it.

Thanks!

Bill

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: How to add a Lucene index to a jar file?

Posted by Doug Cutting <cu...@apache.org>.
David Spencer wrote:
> Isn't "ZipDirectory" the thing to search for?

I think it's actually URLDirectory:

http://www.mail-archive.com/lucene-dev@jakarta.apache.org/msg02453.html

Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: How to add a Lucene index to a jar file?

Posted by David Spencer <da...@tropo.com>.
Doug Cutting wrote:

> Miles Barr wrote:
> 
>> You'll have to implement org.apache.lucene.store.Directory to load the
>> index from the JAR file. Take a look at FSDirectory and RAMDirectory for
>> some more details.
>>
>> Then you have either load the JAR file with java.util.jar.JarFile to get
>> to the files or you can use Classloader#getResourceAsStream to get to
>> them.
> 
> 
> The problem is that a jar file entry becomes an InputStream, but 
> InputStream is not random access, and Lucene requires random access.  So 
> you need to extract the index either to disk or RAM in order to get 
> random access.  I think folks have posted code for this to the list 

Isn't "ZipDirectory" the thing to search for?

> previously.
> 
> Doug
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: How to add a Lucene index to a jar file?

Posted by Luke Francl <lu...@stellent.com>.
On Mon, 2005-01-17 at 13:10, Doug Cutting wrote:

> The problem is that a jar file entry becomes an InputStream, but 
> InputStream is not random access, and Lucene requires random access.  So 
> you need to extract the index either to disk or RAM in order to get 
> random access.  I think folks have posted code for this to the list 
> previously.

I think it would be cool if Lucene included a class that facilitated
creating a RAMDirectory from an index in a JAR file, for the kind of
point-and-click startup that Bill is talking about.

Regards,
Luke Francl


---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: How to add a Lucene index to a jar file?

Posted by Doug Cutting <cu...@apache.org>.
Miles Barr wrote:
> You'll have to implement org.apache.lucene.store.Directory to load the
> index from the JAR file. Take a look at FSDirectory and RAMDirectory for
> some more details.
> 
> Then you have either load the JAR file with java.util.jar.JarFile to get
> to the files or you can use Classloader#getResourceAsStream to get to
> them.

The problem is that a jar file entry becomes an InputStream, but 
InputStream is not random access, and Lucene requires random access.  So 
you need to extract the index either to disk or RAM in order to get 
random access.  I think folks have posted code for this to the list 
previously.

Doug

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org


Re: How to add a Lucene index to a jar file?

Posted by Miles Barr <mi...@runtime-collective.com>.
On Mon, 2005-01-17 at 10:25 -0800, Bill Janssen wrote:
> I'd like to package up a Lucene index with the Lucene class files and
> my own application classes into a single jar file, so that it forms a
> "double-clickable" single-file Java application that supports
> searching over the index.  However, I'm not sure how to read the index
> (create an IndexReader) if the files that form the index are packaged
> into the same jar file with the code.
> 
> If anyone could shed some light on how to do this, I'd appreciate it.


You'll have to implement org.apache.lucene.store.Directory to load the
index from the JAR file. Take a look at FSDirectory and RAMDirectory for
some more details.

Then you have either load the JAR file with java.util.jar.JarFile to get
to the files or you can use Classloader#getResourceAsStream to get to
them.




-- 
Miles Barr <mi...@runtime-collective.com>
Runtime Collective Ltd.

---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org