从命令行覆盖 solr 上的 contextPath

Override contextPath on solr start from command line

是否可以在使用命令行参数启动 Solr 5 时覆盖 jetty "contextPath" 属性? 我想要类似

的东西
bin/solr -p 8983 -s "example/techproducts/solr" -a "-DcontextPath=/s"

所以基数 url 将是 http://localhost:8983/s

准确地说,我想完全覆盖 contextPath 属性

你的问题是关于 solr 作为 jetty webapp 的上下文路径。

而不是

http://localhost:8983/solr/ 

您想通过

访问 solr
http://localhost:8983/s/

恕我直言,如果不更改配置文件,这是不可能的。

请注意,对于 zookeeper 和 solrCloud,有参数 hostContext in solr.xml and you can use system properties in solr.xml like hostContext

没有 zookeeper 但有变化

server\contexts\solr-jetty-context.xml

你会得到你想要的:

变化自

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath"><Property name="hostContext" default="/solr"/></Set>
  <Set name="war"><Property name="jetty.base"/>/solr-webapp/webapp</Set>
  <Set name="defaultsDescriptor"><Property name="jetty.base"/>/etc/webdefault.xml</Set>
  <Set name="extractWAR">false</Set>
</Configure>

对此:

<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
  <Set name="contextPath"><SystemProperty name="hostContext" default="/solr"/></Set>
  <Set name="war"><Property name="jetty.base"/>/solr-webapp/webapp</Set>
  <Set name="defaultsDescriptor"><Property name="jetty.base"/>/etc/webdefault.xml</Set>
  <Set name="extractWAR">false</Set>
</Configure>

现在您可以从

开始
solr start -a "-DhostContext=/s"