You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Robert Krüger <kr...@lesspain.de> on 2014/02/11 11:41:12 UTC

Set up embedded Solr container and cores programmatically to read their configs from the classpath

Hi,

I have an application with an embedded Solr instance (and I want to
keep it embedded) and so far I have been setting up my Solr
installation programmatically using folder paths to specify where the
specific container or core configs are.

I have used the CoreContainer methods createAndLoad and create using
File arguments and this works fine. However, now I want to change this
so that all configuration files are loaded from certain locations
using the classloader but I have not been able to get this to work.

E.g. I want to have my solr config located in the classpath at

my/base/package/solr/conf

and the core configs at

my/base/package/solr/cores/core1/conf,
my/base/package/solr/cores/core2/conf

etc..

Is this possible at all? Looking through the source code it seems that
specifying classpath resources in such a qualified way is not
supported but I may be wrong.

I could get this to work for the container by supplying my own
implementation of SolrResourceLoader that allows a base path to be
specified for the resources to be loaded (I first thought that would
happen already when specifying instanceDir accordingly but looking at
the code it does not. for resources loaded through the classloader,
instanceDir is not prepended). However then I am stuck with the
loading of the cores' resources as the respective code (see
org.apache.solr.core.CoreContainer#createFromLocal) instantiates a
SolResourceLoader internally.

Thanks for any help with this (be it a clarification that it is not possible).

Robert

Re: Set up embedded Solr container and cores programmatically to read their configs from the classpath

Posted by Alan Woodward <al...@flax.co.uk>.
Hi Robert,

I don't think this is possible at the moment, but I hope to get https://issues.apache.org/jira/browse/SOLR-4478 in for Lucene/Solr 4.7, which should allow you to inject your own SolrResourceLoader implementation for core creation (it sounds as though you want to wrap the core's loader in a ClasspathResourceLoader).  You could try applying that patch to your setup and see if that helps you out.

Alan Woodward
www.flax.co.uk


On 11 Feb 2014, at 10:41, Robert Krüger wrote:

> Hi,
> 
> I have an application with an embedded Solr instance (and I want to
> keep it embedded) and so far I have been setting up my Solr
> installation programmatically using folder paths to specify where the
> specific container or core configs are.
> 
> I have used the CoreContainer methods createAndLoad and create using
> File arguments and this works fine. However, now I want to change this
> so that all configuration files are loaded from certain locations
> using the classloader but I have not been able to get this to work.
> 
> E.g. I want to have my solr config located in the classpath at
> 
> my/base/package/solr/conf
> 
> and the core configs at
> 
> my/base/package/solr/cores/core1/conf,
> my/base/package/solr/cores/core2/conf
> 
> etc..
> 
> Is this possible at all? Looking through the source code it seems that
> specifying classpath resources in such a qualified way is not
> supported but I may be wrong.
> 
> I could get this to work for the container by supplying my own
> implementation of SolrResourceLoader that allows a base path to be
> specified for the resources to be loaded (I first thought that would
> happen already when specifying instanceDir accordingly but looking at
> the code it does not. for resources loaded through the classloader,
> instanceDir is not prepended). However then I am stuck with the
> loading of the cores' resources as the respective code (see
> org.apache.solr.core.CoreContainer#createFromLocal) instantiates a
> SolResourceLoader internally.
> 
> Thanks for any help with this (be it a clarification that it is not possible).
> 
> Robert