ElasticSearch 和 Java 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25579876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ElasticSearch and Java environment variable
提问by ahnbizcad
For Windows 7, I've installed JDK in both 32 and 64 bit versions. The versions are 8, update 20 for all four installations. http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
对于 Windows 7,我已经安装了 32 位和 64 位版本的 JDK。所有四个安装的版本都是 8,更新 20。 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
when I download and unzip elasticsearch, and run /bin/service.bat or /bin/elasticsearch.bat files, I get in my terminal:
当我下载并解压缩 elasticsearch 并运行 /bin/service.bat 或 /bin/elasticsearch.bat 文件时,我进入了我的终端:
JAVA_HOME environment variable must be set!
Press any key to continue . . .
JAVA_HOME environment variable must be set!
Press any key to continue . . .
When I do, the terminal closes.
当我这样做时,终端关闭。
I've uninstalled and reinstalled, but that didn't fix it. Why wouldn't the environment varaible get set? Is it an installation thing, or do I actually have to manually set the variable. It just seems like if it installed correctly, it would set the variable automatically... Please help. Thanks
我已经卸载并重新安装,但这并没有解决它。为什么不设置环境变量?这是安装问题,还是我实际上必须手动设置变量。看起来如果它安装正确,它会自动设置变量......请帮忙。谢谢
I've manually set the JAVA_HOME environment variable using this.
我已经使用它手动设置了 JAVA_HOME 环境变量。
https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
https://confluence.atlassian.com/display/DOC/Setting+the+JAVA_HOME+Variable+in+Windows
My path is C:\Progra~1\Java\jdk1.8.0_20\jre
我的路径是 C:\Progra~1\Java\jdk1.8.0_20\jre
Now, when I run service.bat, the terminal immediately closes upon opening. When I run elasticsearch.bat, the terminal prints some lines, and after a while, it just stays there, and I can't type anything.
现在,当我运行 service.bat 时,终端在打开时立即关闭。当我运行 elasticsearch.bat 时,终端会打印一些行,一段时间后,它就停留在那里,我无法输入任何内容。
EDIT:
编辑:
I uninstalled all java, reinstalled only the JRE 64 bit, and set the system environment variable to JAVA_HOME
and `C:\Progra~1\Java\jre1.8.0_20
我卸载了所有java,只重新安装了JRE 64位,并将系统环境变量设置为JAVA_HOME
`C:\Progra~1\Java\jre1.8.0_20
I have discovered that there is CLASSPATH
that's set to a 32bit, older java version. Should I delete that variable?
我发现有CLASSPATH
一个设置为 32 位的旧 Java 版本。我应该删除那个变量吗?
采纳答案by prayagupd
STEP 1
第1步
Can you verify JAVA_HOME
is set to C:\Progra~1\Java\jdk1.8.0_20
,
你能验证JAVA_HOME
设置为C:\Progra~1\Java\jdk1.8.0_20
,
C:\>echo %JAVA_HOME%
Also, verify java
command is available,
此外,验证java
命令可用,
java -version
Reference
参考
Check if JAVA_HOME is present in environment using batch script
STEP 2
第2步
If JAVA_HOME
is not set, please follow the steps provided here - How to Set Java Home in windows
如果JAVA_HOME
未设置,请按照此处提供的步骤操作 -如何在 Windows 中设置 Java Home
总结,
- Right-click the My Computer iconon your desktop and select Properties.
- Click the Advanced tab. Click the Environment Variablesbutton. Under System Variables, click New.
- Enter the variable name as JAVA_HOME.
Enter the variable value as the installation path for the JDK.
(eg.
C:\Progra~1\Java\jdk1.8.0_20
).- Click OK.
- Click Apply Changes.
- 右键单击桌面上的“我的电脑”图标,然后选择“属性”。
- 单击高级选项卡。单击环境变量按钮。在系统变量下,单击新建。
- 输入变量名作为 JAVA_HOME。
输入变量值作为 JDK 的安装路径。
(例如。
C:\Progra~1\Java\jdk1.8.0_20
)。- 单击确定。
- 单击应用更改。
回答by breght
You can set the system-wide environment variables by clicking Start, pointing to 'Computer', right-clicking and selecting properties. Next, click 'Advanced System Settings', hitting the 'Advanced' tab and selecting the 'Environment Variables' button. This brings up a window where you can set your JAVA_HOM
E variable. You can do this either for the current user (top box) or system-wide.
您可以通过单击开始,指向“计算机”,右键单击并选择属性来设置系统范围的环境变量。接下来,单击“高级系统设置”,点击“高级”选项卡并选择“环境变量”按钮。这会打开一个窗口,您可以在其中设置JAVA_HOM
E 变量。您可以为当前用户(顶盒)或系统范围执行此操作。
After doing this, open a new cmd window (Start menu, type 'cmd
' and hit enter) and verify JAVA_HOME
is set like in the question above.
执行此操作后,打开一个新的 cmd 窗口(开始菜单,键入“ cmd
”并按 Enter)并验证JAVA_HOME
是否设置为如上问题。
回答by BatScream
A workaround if you do not have privileges to set up the environmental variables:
如果您没有设置环境变量的权限,则解决方法:
open the elasticsearch.bat file,
打开elasticsearch.bat文件,
a) Remove the line:
a) 删除该行:
if NOT DEFINED JAVA_HOME goto err
b) Replace %JAVA_HOME% with your java jdk path, something like: C:\Program Files\Java\jdk1.7.0_51
b) 将 %JAVA_HOME% 替换为您的 java jdk 路径,例如:C:\Program Files\Java\jdk1.7.0_51
And for your terminal getting started and you not being able to type anything, it is the elasticsearch server, you need to connect to it using a client like cygwin.
对于您的终端开始并且您无法输入任何内容,它是 elasticsearch 服务器,您需要使用像 cygwin 这样的客户端连接到它。
https://cygwin.com/install.html
https://cygwin.com/install.html
For connecting to the server refer the elasticsearch documentation.
要连接到服务器,请参阅 elasticsearch 文档。
http://www.elasticsearch.org/guide/
http://www.elasticsearch.org/guide/
A similar question has already been answered:
已经回答了一个类似的问题:
回答by VISHNU Radhakrishnan
run the below command:
运行以下命令:
set JAVA_HOME=C:\Program Files\Java\jre8
回答by Vijay Sutaria
I was facing similar issue where Java home is already set but still it was throwing error. Open elasticsearch-plugin.bat file and change "IF DEFINED JAVA_HOME" to "IF DEFINED %JAVA_HOME%" , if you have java home already set.
我遇到了类似的问题,其中 Java home 已经设置,但仍然抛出错误。打开 elasticsearch-plugin.bat 文件并将 "IF DEFINED JAVA_HOME" 更改为 "IF DEFINED %JAVA_HOME%" ,如果您已经设置了 java home 。
Thanks
谢谢
回答by mohan08p
This is pretty common error, JAVA_HOME environment is not set. So, we need to set it up in a more prominent basis. What it's asking for the path to the jredirectory and not to the bin directory i.e. java environment path to configure & run the elasticsearch. So, make sure you don't specify the bin directory into your path. Then, you are good to go run your elasticsearch and it will be up and running at default port 9200.
这是很常见的错误,未设置 JAVA_HOME 环境。所以,我们需要把它放在一个更突出的基础上。它要求的是jre目录的路径而不是 bin 目录的路径,即配置和运行 elasticsearch 的 java 环境路径。因此,请确保不要在路径中指定 bin 目录。然后,您可以运行您的 elasticsearch,它将在默认端口 9200 上启动并运行。
回答by Ivan Yurchenko
I still couldn't run it even after I set the %JAVA_HOME%
environment variable. The problem for me was that I should have ran the elasticsearch.bat
file as an administrator. That fixed the issue.
即使我设置了%JAVA_HOME%
环境变量,我仍然无法运行它。我的问题是我应该elasticsearch.bat
以管理员身份运行该文件。这解决了问题。
回答by Ankit Saxena
See , you just need to do below: (don't delete any environment variable already set)
看,你只需要在下面做:(不要删除任何已经设置的环境变量)
- Step 1: Edit elasticsearch-service.bat located in \bin
- Step 2: Add below line at the beginning (below @echo) SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_162 (or your Java path)
- Step 3: locate %%JAVA_HOME%% in the same file and replace it with %JAVA_HOME%
- Step 4: then from cmd in bin folder run: elasticsearch-service.bat install
- Step 5: That's it, simply run elasticsearch-service now from cmd and it will run.
- 步骤 1:编辑位于 \bin 中的 elasticsearch-service.bat
- 第 2 步:在开头添加以下行(@echo 下方)SET JAVA_HOME=C:\Program Files\Java\jdk1.8.0_162(或您的 Java 路径)
- 第三步:在同一个文件中找到%%JAVA_HOME%%,替换成%JAVA_HOME%
- 第 4 步:然后从 bin 文件夹中的 cmd 运行:elasticsearch-service.bat install
- 第 5 步:就是这样,现在只需从 cmd 运行 elasticsearch-service 即可运行。
回答by Rodolfo Luna
I get this error because I was using Powershell
and it wasn't seeing environment variable
. (I don't know way)
Then I used CMD
and it ran successfully.
我收到此错误是因为我正在使用Powershell
但没有看到environment variable
. (我不知道如何)然后我使用CMD
并成功运行。
回答by fgul
If elasticsearch version is 7.5 or higher, you find elasticsearch-7.X.Y\bindirectory and then edit the elasticsearch-env.batas the following:
如果elasticsearch版本是7.5或更高,你会找到elasticsearch-7.XY\bin目录,然后编辑elasticsearch -env.bat如下:
if defined JAVA_HOME (
set JAVA="%WRITE_ELASTICSEARCH_JAVA_PATH%\bin\java.exe" //write java custom path. Edit only this line
set JAVA_TYPE=JAVA_HOME
) else (
set JAVA="%ES_HOME%\jdk\bin\java.exe"
set JAVA_HOME="%ES_HOME%\jdk"
set JAVA_TYPE=bundled jdk
)
You can customize the java path like that for elasticsearch.
您可以像elasticsearch那样自定义java路径。