解决es9.x安装错误:NoSuchFileException: D:\app\elasticsearch%JAVA_HOME%\lib\dt.jar
报错信息
D:\app\elasticsearch-8.12.2\bin>elasticsearch.bat
warning: ignoring JAVA_HOME=D:\env\java\jdk-8\jdk-1.8; using bundled JDK
CompileCommand: exclude org/apache/lucene/util/MSBRadixSorter.computeCommonPrefixLengthAndBuildHistogram bool exclude = true
CompileCommand: exclude org/apache/lucene/util/RadixSelector.computeCommonPrefixLengthAndBuildHistogram bool exclude = true
????? 05, 2025 9:13:59 ???? sun.util.locale.provider.LocaleProviderAdapter <clinit>
WARNING: COMPAT locale provider will be removed in a future release
[2025-12-05T09:14:00,238][ERROR][o.e.b.Elasticsearch ] [I-PC-065568] fatal exception while booting Elasticsearchjava.nio.file.NoSuchFileException: D:\app\elasticsearch-8.12.2%JAVA_HOME%\lib\dt.jar
at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:85)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:53)
at java.base/sun.nio.fs.WindowsFileAttributeViews$Basic.readAttributes(WindowsFileAttributeViews.java:38)
See logs for more details.
ERROR: Elasticsearch did not exit normally - check the logs at D:\app\elasticsearch-8.12.2\logs\elasticsearch.log
ERROR: Elasticsearch exited unexpectedly, with exit code 1
报错原因:

本地java环境配置的时候设置过CLASSPATH 环境变量。
在 Java 的早期(大约是 JDK 1.4 之前),CLASSPATH 环境变量是至关重要的。那时候:
没有构建工具:当时没有像 Maven、Gradle 这样的自动化构建和依赖管理工具。
手动管理 JAR 包:开发者需要手动下载所有需要的第三方 JAR 包,并把它们放在一个或多个文件夹里。
全局通知 JVM:为了让 java.exe 和 javac.exe 知道去哪里找这些 JAR 包和 .class 文件,开发者必须在操作系统的 CLASSPATH 环境变量里,把所有这些 JAR 包的路径和类的根目录一个个手动列出来。
那时候的 CLASSPATH 可能长这样:
C:\libs\junit.jar;C:\libs\log4j.jar;D:\myproject\classes
这种方式非常原始,并且带来了无穷的麻烦,被称为 “JAR Hell” (JAR 地狱):
版本冲突:两个不同的项目可能需要同一个库的不同版本,但全局 CLASSPATH 只能设置一个。
环境污染:一个项目设置的 CLASSPATH 可能会意外地影响到系统上运行的另一个完全不相关的 Java 程序。
部署困难:把应用部署到另一台机器上时,需要手动在那台机器上配置一模一样的 CLASSPATH,极其繁琐且容易出错。
es8.x之后自带jdk,不使用系统的jdk ,但是系统原本的classpath变量的%JAVA_HOME%\lib\dt.jar 会导致es的文件加载错误
解决方案:
方法一:
打开一个全新的 CMD 命令行窗口。
输入以下命令,在当前窗口中清空 CLASSPATH:
set CLASSPATH=
现在,在这个窗口里启动 Elasticsearch:
\bin\elasticsearch.bat
方法二:
修改elasticsearch-env.bat文件尾部 让他忽略 CLASSPATH:
原本底部是这样:
rem warn that we are not observing the value of $JAVA_HOME
if defined JAVA_HOME (
echo warning: ignoring JAVA_HOME=%JAVA_HOME%; using %JAVA_TYPE% >&2
)
rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
rem warn them that we are not observing the value of %JAVA_OPTS%
if defined JAVA_OPTS (
(echo|set /p=warning: ignoring JAVA_OPTS=%JAVA_OPTS%; )
echo pass JVM parameters via ES_JAVA_OPTS
)
cd %ES_HOME%
增加
rem do not let CLASSPATH slip in (as the JVM does by default)
if defined CLASSPATH (
echo warning: ignoring CLASSPATH=%CLASSPATH%
set CLASSPATH=
)
改完之后是这样:
rem warn that we are not observing the value of $JAVA_HOME
if defined JAVA_HOME (
echo warning: ignoring JAVA_HOME=%JAVA_HOME%; using %JAVA_TYPE% >&2
)
rem JAVA_OPTS is not a built-in JVM mechanism but some people think it is so we
rem warn them that we are not observing the value of %JAVA_OPTS%
if defined JAVA_OPTS (
(echo|set /p=warning: ignoring JAVA_OPTS=%JAVA_OPTS%; )
echo pass JVM parameters via ES_JAVA_OPTS
)
rem do not let CLASSPATH slip in (as the JVM does by default)
if defined CLASSPATH (
echo warning: ignoring CLASSPATH=%CLASSPATH%
set CLASSPATH=
)
cd %ES_HOME%
更多推荐


所有评论(0)