在windows环境idea下编译运行elasticsearch7.14.1(代码片段)

顧棟 顧棟     2022-12-31     768

关键词:

在Windows环境中IDEA下编译运行Elasticsearch 7.14.1

环境准备

  • JDK 16

  • Gradle 7.1

为了更快的下载,可以使用阿里的仓库服务,在解压的文件夹中的init.d文件夹下新建文件init.gradle

allprojects
    repositories 
	    maven url 'https://maven.aliyun.com/repository/public'
	    maven url 'https://maven.aliyun.com/repository/google'
        maven url 'https://maven.aliyun.com/repository/gradle-plugin'
        maven url 'https://maven.aliyun.com/repository/jcenter'
		
        
	
        def REPOSITORY_URL = 'https://maven.aliyun.com/repository/public/'
        all 
            ArtifactRepository repo ->
    if (repo instanceof MavenArtifactRepository) 
                def url = repo.url.toString()
                if (url.startsWith('https://artifacts.elastic.co/maven')
				||url.startsWith('https://repo1.maven.org/maven2') 
				|| url.startsWith('https://repo.maven.org/maven2') 
				|| url.startsWith('https://jcenter.bintray.com/')
				||url.startsWith('https://repo.maven.apache.org/maven2')
				) 
                    project.logger.lifecycle "Repository $repo.url replaced by $REPOSITORY_URL."
                    remove repo
                
            
        
        maven 
            url REPOSITORY_URL
        
    

  • Git 2.23

  • IDEA 2021.2

  • Elasticsearch Windows版的发布包

如何确认JDK以及Gradle的版本

操作步骤

获取源码

方式一:直接通过git bash执行git clone命令

打开这个命名行工具,git clone https://github.com/elastic/elasticsearch.git,切换到7.14分支上。

方式二:通过IDEA界面化操作



通过右下角工具获取远程分支到本地

github仓库比较卡,可以使用gitee与github做映射,先同步至gitee上,在从gitee上进行clone。

编译源码

用IDEA打开项目工程。

配置Gradle

自动编译

本地运行

VM配置

-Des.path.home=E:\\tmp\\es\\elasticsearch-7.14.1
-Des.path.conf=E:\\tmp\\es\\elasticsearch-7.14.1\\config
-Dlog4j2.disable.jmx=true
-Xmx4g
-Xms4g

遇到的问题

1. 权限问题

[2021-09-07T17:49:40,721][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: Unknown codebases [codebase.elasticsearch-plugin-classloader, codebase.elasticsearch, codebase.elasticsearch-secure-sm] in policy file [file:/E:/code/source-code/elasticsearch7/server/out/production/resources/org/elasticsearch/bootstrap/security.policy]
Available codebases: [codebase.jna-5.7.0-1.jar, codebase.lucene-grouping, codebase.t-digest-3.2.jar, codebase.joda-time, codebase.lucene-analyzers-common-8.9.0.jar, codebase.lucene-backward-codecs, codebase.joda-time-2.10.10.jar, codebase.lucene-highlighter, codebase.log4j-api-2.11.1.jar, codebase.lucene-memory, codebase.jopt-simple, codebase.jts-core, codebase.lucene-suggest-8.9.0.jar, codebase.hppc, codebase.jna, codebase.hppc-0.8.1.jar, codebase.spatial4j-0.7.jar, codebase.lucene-join, codebase.log4j-api, codebase.HdrHistogram, codebase.jackson-dataformat-cbor, codebase.lucene-core, codebase.lucene-spatial3d-8.9.0.jar, codebase.spatial4j, codebase.log4j-core-2.11.1.jar, codebase.snakeyaml-1.26.jar, codebase.snakeyaml, codebase.jackson-dataformat-yaml-2.10.4.jar, codebase.lucene-backward-codecs-8.9.0.jar, codebase.lucene-spatial-extras-8.9.0.jar, codebase.HdrHistogram-2.1.9.jar, codebase.lucene-misc-8.9.0.jar, codebase.t-digest, codebase.lucene-highlighter-8.9.0.jar, codebase.lucene-join-8.9.0.jar, codebase.lucene-analyzers-common, codebase.jackson-dataformat-cbor-2.10.4.jar, codebase.lucene-queryparser-8.9.0.jar, codebase.lz4-java-1.8.0.jar, codebase.lucene-spatial-extras, codebase.lucene-memory-8.9.0.jar, codebase.lucene-queries-8.9.0.jar, codebase.lucene-queryparser, codebase.jts-core-1.15.0.jar, codebase.jackson-core-2.10.4.jar, codebase.lz4-java, codebase.jackson-dataformat-yaml, codebase.jackson-core, codebase.log4j-core, codebase.lucene-queries, codebase.lucene-grouping-8.9.0.jar, codebase.lucene-sandbox, codebase.lucene-suggest, codebase.lucene-sandbox-8.9.0.jar, codebase.jackson-dataformat-smile, codebase.jopt-simple-5.0.2.jar, codebase.lucene-misc, codebase.lucene-spatial3d, codebase.lucene-core-8.9.0.jar, codebase.jackson-dataformat-smile-2.10.4.jar]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:163) ~[classes/:?]
	at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:150) ~[classes/:?]
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75) ~[classes/:?]
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:116) ~[classes/:?]
	at org.elasticsearch.cli.Command.main(Command.java:79) ~[classes/:?]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:115) ~[classes/:?]
	at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:81) ~[classes/:?]
Caused by: java.lang.IllegalArgumentException: Unknown codebases [codebase.elasticsearch-plugin-classloader, codebase.elasticsearch, codebase.elasticsearch-secure-sm] in policy file [file:/E:/code/source-code/elasticsearch7/server/out/production/resources/org/elasticsearch/bootstrap/security.policy]
Available codebases: [codebase.jna-5.7.0-1.jar, codebase.lucene-grouping, codebase.t-digest-3.2.jar, codebase.joda-time, codebase.lucene-analyzers-common-8.9.0.jar, codebase.lucene-backward-codecs, codebase.joda-time-2.10.10.jar, codebase.lucene-highlighter, codebase.log4j-api-2.11.1.jar, codebase.lucene-memory, codebase.jopt-simple, codebase.jts-core, codebase.lucene-suggest-8.9.0.jar, codebase.hppc, codebase.jna, codebase.hppc-0.8.1.jar, codebase.spatial4j-0.7.jar, codebase.lucene-join, codebase.log4j-api, codebase.HdrHistogram, codebase.jackson-dataformat-cbor, codebase.lucene-core, codebase.lucene-spatial3d-8.9.0.jar, codebase.spatial4j, codebase.log4j-core-2.11.1.jar, codebase.snakeyaml-1.26.jar, codebase.snakeyaml, codebase.jackson-dataformat-yaml-2.10.4.jar, codebase.lucene-backward-codecs-8.9.0.jar, codebase.lucene-spatial-extras-8.9.0.jar, codebase.HdrHistogram-2.1.9.jar, codebase.lucene-misc-8.9.0.jar, codebase.t-digest, codebase.lucene-highlighter-8.9.0.jar, codebase.lucene-join-8.9.0.jar, codebase.lucene-analyzers-common, codebase.jackson-dataformat-cbor-2.10.4.jar, codebase.lucene-queryparser-8.9.0.jar, codebase.lz4-java-1.8.0.jar, codebase.lucene-spatial-extras, codebase.lucene-memory-8.9.0.jar, codebase.lucene-queries-8.9.0.jar, codebase.lucene-queryparser, codebase.jts-core-1.15.0.jar, codebase.jackson-core-2.10.4.jar, codebase.lz4-java, codebase.jackson-dataformat-yaml, codebase.jackson-core, codebase.log4j-core, codebase.lucene-queries, codebase.lucene-grouping-8.9.0.jar, codebase.lucene-sandbox, codebase.lucene-suggest, codebase.lucene-sandbox-8.9.0.jar, codebase.jackson-dataformat-smile, codebase.jopt-simple-5.0.2.jar, codebase.lucene-misc, codebase.lucene-spatial3d, codebase.lucene-core-8.9.0.jar, codebase.jackson-dataformat-smile-2.10.4.jar]
	at org.elasticsearch.bootstrap.PolicyUtil.readPolicy(PolicyUtil.java:261) ~[classes/:?]
	at org.elasticsearch.bootstrap.ESPolicy.<init>(ESPolicy.java:44) ~[classes/:?]
	at org.elasticsearch.bootstrap.Security.configure(Security.java:106) ~[classes/:?]
	at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:214) ~[classes/:?]
	at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:399) ~[classes/:?]
	at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[classes/:?]
	... 6 more

从错误信息看出在server模块下的security.policy文件中存在了对codebase.elasticsearch-plugin-classloader, codebase.elasticsearch, codebase.elasticsearch-secure-sm的使用但是却有加载这几个jar

修改建议:

将关于三个jar的授权信息拷贝至公共授权方法体中,之后注释这三个jar的授权方法体

2. 版本问题

[2021-09-07T17:48:05,568][ERROR][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.IllegalArgumentException: Plugin [repository-url] was built for Elasticsearch version 7.14.1 but version 7.14.2 is running

修改建议:修改文件org.elasticsearch.Version中的对象CURRENT的值为V_7_14_1

3. geoip报错信息

[2021-09-07T17:18:24,147][ERROR][o.e.i.g.GeoIpDownloader  ] [] exception during geoip databases update
java.net.SocketTimeoutException: connect timed out
	at java.net.PlainSocketImpl.waitForConnect(Native Method) ~[?:?]
	at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:107) ~[?:?]
	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[?:?]
	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[?:?]
	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[?:?]
	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[?:?]
	at java.net.Socket.connect(Socket.java:608) ~[?:?]
	at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:287) ~[?:?]
	at sun.net.NetworkClient.doConnect(NetworkClient.java:177) ~[?:?]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:474) ~[?:?]
	at sun.net.www.http.HttpClient.openServer(HttpClient.java:569) ~[?:?]
	at sun.net.www.protocol.https.HttpsClient.<init>(HttpsClient.java:265) ~[?:?]
	at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:372) ~[?:?]
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:203) ~[?:?查看详情  

如何在windows的命令行环境下编译c++程序?

参考技术A你使用VS2008的话,安装完成后选择VisualStudio2008CommandPrompt,出现一个cmd窗口,\\x0d\\x0a使用\\x0d\\x0aclmain.cpp\\x0d\\x0a就可以编译!\\x0d\\x0a如果你的项目比较复杂,就自己写一个Makefile文件吧! 查看详情

怎样将windows下写的c程序在linux下编译运行,谢谢?

参考技术A先确保你的c程序没有调用win下专有的api,比如win32api或.net等,如果有,就需要另写接口层。最好能只调用posix库或跨平台的库,或完全原创的算法库。c程序满足和win专有接口能脱离直接关系,就能在linux下编译。 查看详情

windows下编译luajit

参考技术A这里使用Visualstudio自带的命令行工具来进行编译,所以需要安装好VS。首先打开VS命令行工具。可以按Win+S,输入prompt来找到它。如图。解压LuaJIT源码,并进入到解压目录/src下。输入msvcbuild开始编译。看到===Successfullybuil... 查看详情

在windows环境下编译pb(protobuf)文件

参考技术Aprotoc --plugin=protoc-gen-go.exe  --go_out=.  xx.protoprotoc --plugin=protoc-gen-go.exe  --go-grpc_out=.  xx.proto若提示:--go-grpc_out:protoc-gen-go-grpc:系统找不到指定的文件。需在grpc-go-1.31.0\cmd\protoc-gen-... 查看详情

cygwin和mingw的区别与联系是怎样的

参考技术A1、从目标上说MinGW是让Windows用户可以用上GNU工具,比如GCC。Cygwin提供完整的类Unix环境,Windows用户不仅可以使用GNU工具,理论上Linux上的程序只要用Cygwin重新编译,就可以在Windows上运行。2、从能力上说如果程序只用到C... 查看详情

windows下编译及使用libevent

Libevent官网:http://libevent.org/windows7下编译:编译环境: windows7+VS2010(1)解压libevent到F:libeventlibevent-2.0.21-stable(2)打开Microsoftvisualstudio2010命令行工具(3)修改以下三个文件,添加宏定义:在以下3个文件开头添加“#define_... 查看详情

window下编译cef内核加入mp3/mp4支持

下载depot_tools 解压,加入到环境变量进入cmd(管理员)运行 gclient获取 python和git,svn,设置python环境变量创建新文件夹mkdirchromium&&cdchromium把 automate-git.py 保存到文件夹根目录然后运行命令:setGYP_GENERATORS=... 查看详情

win11环境下编译theia源码

1、安装gitbash\jdk\python\nodejs\yarn;2、安装windows下用于npm构建工具"npm×××tall--global--productionwindows-build-tools";3、屏蔽ffmpeg的构建"exportTHEIA_ELECTRON_SKIP_REPLACE_FFMPEG=1";4、在theia代码目录下执 查看详情

如何在windows下编译openssl

在Windows下编译OpenSSL(VS2010使用VC10的cl编译器)1、安装ActivePerl//初始化的时候,需要用到perl解释器2、使用VS2010下的VisualStudio2010CommandPrompt进入控制台模式(这个模式会自动设置各种环境变量)3、解压缩openssl的包,进入openssl的目录... 查看详情

如何在windows下编译openssl

如何在Windows下编译OpenSSL(VS2010使用VC10的cl编译器)1、安装ActivePerl//初始化的时候,需要用到perl解释器2、使用VS2010下的VisualStudio2010CommandPrompt进入控制台模式(这个模式会自动设置各种环境变量)3、解压缩openssl的包,进入openssl的... 查看详情

如何在windows下编译openssl

如何在Windows下编译OpenSSL(VS2010使用VC10的cl编译器)1、安装ActivePerl//初始化的时候,需要用到perl解释器2、使用VS2010下的VisualStudio2010CommandPrompt进入控制台模式(这个模式会自动设置各种环境变量)3、解压缩openssl的包,进入openssl的... 查看详情

[转]windows下编译及使用libevent

http://www.cnblogs.com/luxiaoxun/p/3603399.html  Libevent官网:http://libevent.org/windows7下编译:编译环境: windows7+VS2010(1)解压libevent到F:libeventlibevent-2.0.21-stable(2)打开Microsoftvisualstud 查看详情

在windows下编译lua

http://blog.csdn.net/yue7603835/article/details/41739085http://blog.csdn.net/birdflyto206/article/details/49403801 BuildingLuaonothersystemsIfyou‘renotusingtheusualUnixtools,thentheinstructionsfo 查看详情

caffe在window下编译(windows7,cuda8.0,matlab接口编译)

1.环境:Windows7,Cuda8.0,显卡GTX1080,Matlab2016a,VS2013 (ps:老板说服务器要装windows系统,没办法,又要折腾一番)2.下载caffe包:https://github.com/BVLC/caffe/tree/windows  按照Github上的命令行就行:    这里的Pro 查看详情

openssl-1.1.1-pre1windows环境下编译

场景         VS2015编译openssl-1.1.1-pre1工具         nasm-2.14rc0-installer-x64.exe     &n 查看详情

如何在windows下编译openssl

1、安装ActivePerl//初始化的时候,需要用到perl解释器2、使用VS2010下的VisualStudio2010CommandPrompt进入控制台模式(这个模式会自动设置各种环境变量)3、解压缩openssl的包,进入openssl的目录4、perlconfigureVC-WIN32尽量在这个目录下执行该命... 查看详情

windows下编译jcef(代码片段)

...文参考官方网站上的jcef编译过程编译成功的环境如下:windows1064bitJDK1.8.0_12164bitPython2.7.13gitversion2.12.1.windows.1cmakeversion3.12.0-rc1VisualStudio2015EnterpriseEdition以上的软件也是官网上要求安装的软件,不过版本稍有不同,官网上的版本要... 查看详情