solr/home 配置解析

众所周知,安装solr的时候需要配置一个solr/home参数,其实就是指定solr的根目录,solr在启动的时候会去这个根目录下加载配置信息。

配置solr/home参数有如下几种方式:

    基于web.xml不推荐

   

       solr/home

       ${the_path_to solr_home}

       java.lang.String

   


   基于JNDI 配置


   ${the_path_to solr_home}" override="true" />


   基于环境变量

   

    在${ tomcat_home}/bin/catalina.sh中添加如下环境变量: 

    export JAVA_OPTS="$JAVA_OPTS -Dsolr.solr.home=${the_path_to solr_home}"


    基于当前路径

 

    启动tomcat时需要cd(切换)到${the_path_to solr_home},然后执行sh ${tomcat_home}/bin/startup.sh


    solr加载solr/home源码

  (变量project定义===>static final String project = "solr";)

public static String locateSolrHome() {
    String home = null;
    // Try JNDI
    try {
      Context c = new InitialContext();
      home = (String)c.lookup("java:comp/env/"+project+"/home");
      log.info("Using JNDI solr.home: "+home );
    } catch (NoInitialContextException e) {
      log.info("JNDI not configured for "+project+" (NoInitialContextEx)");
    } catch (NamingException e) {
      log.info("No /"+project+"/home in JNDI");
    } catch( RuntimeException ex ) {
      log.warn("Odd RuntimeException while testing for JNDI: " + ex.getMessage());
    } 
    // Now try system property
    if( home == null ) {
      String prop = project + ".solr.home";
      home = System.getProperty(prop);
      if( home != null ) {
        log.info("using system property "+prop+": " + home );
      }
    }
    // if all else fails, try 
    if( home == null ) {
      home = project + '/';
      log.info(project + " home defaulted to '" + home + "' (could not find system property or JNDI)");
    }
    return normalizeDir( home );
  }



你可能感兴趣的:(Solr)