elasticsearch6.2.4源码Gradle构建idea环境(2)

Idea 导入ES源码工程

准备工作
1)导入源码前重新启动电脑,保证gradle、jdk9和IntelliJ IDEA 2017.2.3环境是好的

源码根目录
E:\workspace\idea\elasticsearch-6.2.4

导入步骤
根据CONTRIBUTING.md说明:

then `File->New Project From Existing Sources`. 
Point to the root ofthe source directory, 
select`Import project from external model->Gradle`,
enable`Use auto-import`

ES Mian class
org.elasticsearch.bootstrap.Elasticsearch

/**
     * Main entry point for starting elasticsearch
     */
    public static void main(final String[] args) throws Exception {
        // we want the JVM to think there is a security manager installed so that if internal policy decisions that would be based on the
        // presence of a security manager or lack thereof act as if there is a security manager present (e.g., DNS cache policy)
        System.setSecurityManager(new SecurityManager() {
            @Override
            public void checkPermission(Permission perm) {
                // grant all permissions so that we can later set the security manager to the one that we want
            }
        });
        LogConfigurator.registerErrorListener();
        final Elasticsearch elasticsearch = new Elasticsearch();
        int status = main(args, elasticsearch, Terminal.DEFAULT);
        if (status != ExitCodes.OK) {
            exit(status);
        }
    }

启动main

第一次报错

ERROR: the system property [es.path.conf] must be set
Exception in thread "main" java.lang.IllegalStateException: path.home is not configured

解决方法:

根目录新建home和home\config 目录
E:\workspace\idea\elasticsearch-6.2.4\home
E:\workspace\idea\elasticsearch-6.2.4\home\config
下载同版本号的 Elasticsearch6.2.4发行版可以运行的,将其中 config 目录和modules拷贝到 home 目录中,项目启动要用到,保证config里面的配置是对的

配置jvm参数
-Didea.no.launcher=true
-Des.path.conf=E:\workspace\idea\demo\elasticsearch-6.2.4\home\config
-Des.path.home=E:\workspace\idea\demo\elasticsearch-6.2.4\home

继续运行报错

main ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")

解决方法

配置jvm参数
-Dlog4j2.disable.jmx=true

继续运行报错

org.elasticsearch.bootstrap.StartupException: java.lang.IllegalStateException: plugins directory
[E:\workspace\idea\elasticsearch-6.2.4\home\plugins] not found

解决方法

新建目录:E:\workspace\idea\elasticsearch-6.2.4\home\plugins

继续运行报错

[2019-12-05T21:03:31,634][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] fatal error in thread [main], exiting
java.lang.NoClassDefFoundError: org/elasticsearch/plugins/ExtendedPluginsClassLoader

分析源码:

发现 ExtendedPluginsClassLoader 的模块是Provided,导致编译时找不到此类

解决方法

将 Provided 改成 Compile , 但更改会提示 distribution\bwc 有多个版本5.6 和 6.0

解决多版本冲突方法如下:

将多余版本忽略掉,只保留1个版本 6.x

运行继续报错

rg.elasticsearch.bootstrap.StartupException: java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "createClassLoader")

解决方法

新建文件:java.policy
放到目录:E:\workspace\idea\demo\elasticsearch-6.2.4\home\config
内容:
grant {
    permission java.lang.RuntimePermission "createClassLoader";
};
配置jvm参数
-Djava.security.policy==E:\workspace\idea\demo\elasticsearch-6.2.4\home\config\java.policy

最终目录
红色框子目录是新建的目录,其他目录源码自己动态生成的


最终JVM参数

-Didea.no.launcher=true
-Dlog4j2.disable.jmx=true
-Des.path.conf=E:\workspace\idea\demo\elasticsearch-6.2.4\home\config
-Des.path.home=E:\workspace\idea\demo\elasticsearch-6.2.4\home
-Djava.security.policy==E:\workspace\idea\demo\elasticsearch-6.2.4\home\config\java.policy

启动成功

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值