lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jnduan <>
Subject Re: using maven to deploy solr on tomcat
Date Wed, 17 Apr 2013 14:19:13 GMT
hi Adeel,
I have use solr with maven since 2011,and my dependency is not solr but solr-core and some
other dependencies .
therefore,my project structure is just like unpack the solr.war file with out the dir 'WEB-INF/lib'.

So I can write some code work with solr ,e.g. a listener set up system properties 'solr.solr.home'
to the right path before solr is lunch.Even set up some properties for zookeeper in solr 4.2.1.

You said your solr home's source path is 'src/main/resources/solr-dev/',that means the solr
home is 'WEB-INF/classes/solr-dev' at the runtime.Then just use ClassLoader.getResource()
in a ServletContextListener to get the absolute path of solr home ,just like this:

private static final String SOLR_HOME_PROP_NAME = "solr.solr.home";


            try {
                URL url = this.getClass().getClassLoader().getResource("/solr-dev");
                if (url != null) {
                    File file = new File(url.toURI());
                    if (file.exists()) {
              " Set /solr/home to system properties,key:{}, value:{}",SOLR_HOME_PROP_NAME,file.getCanonicalPath());
                        logger.error("Resouce url '/solr' is not exists");
                    logger.error("Can not locate resource url '/solr'");
            } catch (Exception e) {
                logger.error(e.getMessage(), e);

I wish this could help,best regards.

Duan Jienan
在 2013-4-16,上午4:33,Adeel Qureshi <> 写道:

> I am trying to embed solr war in an empty application to be able to use
> maven to deploy the generated war file (that includes solr war) to tomcat.
> My pom file is simple
> <dependencies>
> <dependency>
> <groupId>org.apache.solr</groupId>
> <artifactId>solr</artifactId>
> <version>${solr.version}</version>
> <type>war</type>
> </dependency>
> </dependencies>
> this brings in the solr war but now i need to specify solr home to choose
> between a dev and prod directory as the solr home. So I have setup a env
> variable
> <Environment name="solr/home" override="true" type="java.lang.String"
> value="src/main/resources/solr-dev"/>
> but this leads to absolute path of
> INFO: Using JNDI solr.home: src/main/resources/solr-dev
> INFO: looking for solr.xml:
> C:\springsource\sts-2.8.1.RELEASE\src\main\resources\solr-dev\solr.xml
> notice that its uses the given path as absolute path and obviously doesnt
> ends up looking inside the application directory for these config directory.
> Any help would be appreciate.
> Thanks
> Adeel

View raw message