Intellij Idea 运行Elasticsearch源码 v6.0.0

一、环境
OS:windows 10
IntelliJ IDEA 2018.2.1 (Ultimate Edition)
elasticsearch 源码:git clone https://github.com/elastic/elasticsearch.git
elasticsearch 编译版:https://www.elastic.co/downloads/past-releases/elasticsearch-6-0-0
jdk:1.8.0_181
maven:v3.3.9 http://mirrors.shu.edu.cn/apache/maven/maven-3/
gradle:v4.3 https://services.gradle.org/distributions/
(用过gradle4.3.1和最新的gradle4.10编译,会提示jcenter或者maven仓库gradle-logging-4.3.1/4.10不存在,看仓库确实不存在)

二、编译
1、更换阿里的maven仓库,加速jar包下载。在用户根目录.gradle文件夹(例如我的路径是C:\Users\zhang\.gradle)下添加文件init.gradle,内容如下(要替换的源可根据需要修改):

allprojects{
  repositories {
    def my_repo = 'http://maven.aliyun.com/nexus/content/groups/public/'
      all { ArtifactRepository repo ->
        if(repo instanceof MavenArtifactRepository){
          def url = repo.url.toString()
          if (url.startsWith('https://repo1.maven.org/maven2')) {
            remove repo
          }
       }
    }
    maven {
      url my_repo 
    }
  }
}

2、签出v6.0.0版本的源码
elasticsearch源码根目录运行命令:git checkout -b v6.0 v6.0.0
3、开始编译:gradle idea
4、导入idea,File->New->Project From Existing Sources->Import As Gradle Project->Done

三、配置
1、新建Application,配置参数:
Main class:org.elasticsearch.bootstrap.Elasticsearch
VM options:
-Des.path.home=D:\GithubProjects\elasticsearch-6.0\core -Des.path.conf=D:\GithubProjects\elasticsearch-6.0\core\config
Working directory:D:\GithubProjects\elasticsearch-6.0
Use classpath of module:core_main

如下图所示:
Intellij Idea 运行Elasticsearch源码 v6.0.0_第1张图片
2、拷贝需要的模块
将对应编译版的config modules plugins目录拷贝到v6.0源码的core目录下,包结构如下图所示:
Intellij Idea 运行Elasticsearch源码 v6.0.0_第2张图片

四、运行
遇到的错误及解决方法:
1、ERROR Could not register mbeans java.security.AccessControlException: access denied ("javax.management.MBeanTrustPermission" "register")

C:\Program Files\Java\jdk1.8.0_181\jre\lib\security\java.policy文件中添加权限permission javax.management.MBeanTrustPermission “register”;(路径修改成本机环境的jdk路径)

2、java.lang.StringIndexOutOfBoundsException: String index out of range: -1

org.elasticsearch.bootstrap.Security类 static Policy readPolicy(URL policyFile, Set codebases) 方法 esVersion变量更改:
由 final String esVersion = Version.CURRENT + (Build.CURRENT.isSnapshot() ? “-SNAPSHOT” : “”);
改为 final String esVersion = Version.CURRENT + (Build.CURRENT.isSnapshot() ? “” : “”);

五、验证
http://localhost:9200/


{
  "name" : "h1euXqN",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "T7ELiSqcRdKN7teMqAZHfQ",
  "version" : {
    "number" : "6.0.0",
    "build_hash" : "Unknown",
    "build_date" : "Unknown",
    "build_snapshot" : true,
    "lucene_version" : "7.0.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

你可能感兴趣的:(elasticsearch学习)