public class ElasticSearch extends Bootstrap {
public static void close(String[] args) {
Bootstrap.close(args);
}
public static void main(String[] args) {
Bootstrap.main(args);
}
}
直接调用的是Bootstrap.main方法,也就是说我们直接运行Bootstrap类,跟运行ElasticSearch是一样的。我以Bootstrap类启动为例,运行后大家会发现控制台没有输出,我开始以为是log4j配置问题, 找到org.elasticsearch.common.logging.log4j.LogConfigurator 发现配置应该不可能有问题,最后在Bootstrap类找到了原因
boolean foreground = System.getProperty("es.foreground", System.getProperty("es-foreground")) != null;
// handle the wrapper system property, if its a service, don't run as a service
if (System.getProperty("wrapper.service", "XXX").equalsIgnoreCase("true")) {
foreground = false;
}
...
if (!foreground) {
Loggers.disableConsoleLogging();
System.out.close();
}
foreground为false 把控制台关闭了,把foreground设置为true即可,源码环境就搭建完了。