Neither the JAVA_HOME nor the JRE_HOME environment variable is defined At least one of these environ

博主猫头虎的技术世界

🌟 欢迎来到猫头虎的博客 — 探索技术的无限可能!

专栏链接

🔗 精选专栏

领域矩阵

🌐 猫头虎技术领域矩阵
深入探索各技术领域,发现知识的交汇点。了解更多,请访问:

在这里插入图片描述

在这里插入图片描述 解决 “Neither the JAVA_HOME nor the JRE_HOME environment variable is defined” 的问题通常涉及到在你的操作系统中设置环境变量。这个错误通常在尝试运行依赖于Java的应用程序,如Apache Tomcat服务器时出现。下面是针对不同操作系统的解决方法:

Windows 系统

  1. 下载并安装Java:
    确保你已经安装了Java(JRE或JDK)。如果没有,可以从 Oracle 官网 下载并安装。

  2. 设置JAVA_HOME环境变量:

    • 打开“控制面板” > “系统” > “高级系统设置”。
    • 点击“环境变量”。
    • 在“系统变量”部分,点击“新建”。
    • 输入变量名为 JAVA_HOME
    • 变量值应该是你的JDK安装路径,例如 C:\Program Files\Java\jdk-11.0.1(根据你的实际安装路径调整)。
    • 点击“确定”。
  3. 更新系统路径:

    • 在“环境变量”窗口,找到并选中“Path”变量,然后点击“编辑”。
    • 添加一个新条目,输入 %JAVA_HOME%\bin
    • 点击“确定”。
  4. 重启你的计算机或者命令行工具。

MacOS 或 Linux 系统

  1. 安装Java:

    • 可以通过官网下载,或者使用包管理器安装,例如在Mac上使用 brew install java,在Ubuntu上使用 sudo apt-get install default-jdk
  2. 设置JAVA_HOME环境变量:

    • 打开你的终端。
    • 编辑你的profile文件,如 ~/.bash_profile, ~/.zshrc, 或 ~/.bashrc(这取决于你使用的shell)。
    • 添加以下行:
      export JAVA_HOME=$(/usr/libexec/java_home)
      export PATH=$JAVA_HOME/bin:$PATH
      
    • 保存并关闭文件。
    • 执行 source ~/.bash_profile(或相应的文件名),以应用更改。
  3. 重新加载或打开新的终端窗口,以确保环境变量生效。

验证设置

  • 在命令行运行 java -versionecho $JAVA_HOME(Windows中使用 echo %JAVA_HOME%)来验证Java版本和JAVA_HOME变量是否正确设置。

如果在完成这些步骤后,你仍然遇到问题,可能需要检查你的Java安装或重新启动计算机。

@echo off
rem Licensed to the Apache Software Foundation (ASF) under one or more
rem contributor license agreements.  See the NOTICE file distributed with
rem this work for additional information regarding copyright ownership.
rem The ASF licenses this file to You under the Apache License, Version 2.0
rem (the "License"); you may not use this file except in compliance with
rem the License.  You may obtain a copy of the License at
rem
rem     http://www.apache.org/licenses/LICENSE-2.0
rem
rem Unless required by applicable law or agreed to in writing, software
rem distributed under the License is distributed on an "AS IS" BASIS,
rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
rem See the License for the specific language governing permissions and
rem limitations under the License.

rem ---------------------------------------------------------------------------
rem Set JAVA_HOME or JRE_HOME if not already set, ensure any provided settings
rem are valid and consistent with the selected start-up options and set up the
rem endorsed directory.
rem ---------------------------------------------------------------------------

rem Make sure prerequisite environment variables are set

rem In debug mode we need a real JDK (JAVA_HOME)
if ""%1"" == ""debug"" goto needJavaHome

rem Otherwise either JRE or JDK are fine
if not "%JRE_HOME%" == "" goto gotJreHome
if not "%JAVA_HOME%" == "" goto gotJavaHome
echo Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
echo At least one of these environment variable is needed to run this program
goto exit

:needJavaHome
rem Check if we have a usable JDK
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\jdb.exe" goto noJavaHome
if not exist "%JAVA_HOME%\bin\javac.exe" goto noJavaHome
set "JRE_HOME=%JAVA_HOME%"
goto okJava

:noJavaHome
echo The JAVA_HOME environment variable is not defined correctly.
echo It is needed to run this program in debug mode.
echo NB: JAVA_HOME should point to a JDK not a JRE.
goto exit

:gotJavaHome
rem No JRE given, use JAVA_HOME as JRE_HOME
set "JRE_HOME=%JAVA_HOME%"

:gotJreHome
rem Check if we have a usable JRE
if not exist "%JRE_HOME%\bin\java.exe" goto noJreHome
goto okJava

:noJreHome
rem Needed at least a JRE
echo The JRE_HOME environment variable is not defined correctly
echo This environment variable is needed to run this program
goto exit

:okJava
rem Don't override the endorsed dir if the user has set it previously
if not "%JAVA_ENDORSED_DIRS%" == "" goto gotEndorseddir
rem Java 9 no longer supports the java.endorsed.dirs
rem system property. Only try to use it if
rem CATALINA_HOME/endorsed exists.
if not exist "%CATALINA_HOME%\endorsed" goto gotEndorseddir
set "JAVA_ENDORSED_DIRS=%CATALINA_HOME%\endorsed"
:gotEndorseddir

rem Don't override _RUNJAVA if the user has set it previously
if not "%_RUNJAVA%" == "" goto gotRunJava
rem Set standard command for invoking Java.
rem Also note the quoting as JRE_HOME may contain spaces.
set _RUNJAVA="%JRE_HOME%\bin\java.exe"
:gotRunJava

rem Don't override _RUNJDB if the user has set it previously
rem Also note the quoting as JAVA_HOME may contain spaces.
if not "%_RUNJDB%" == "" goto gotRunJdb
set _RUNJDB="%JAVA_HOME%\bin\jdb.exe"
:gotRunJdb

goto end

:exit
exit /b 1

:end
exit /b 0
 

👉 更多信息:有任何疑问或者需要进一步探讨的内容,欢迎点击下方文末名片获取更多信息。我是猫头虎博主,期待与您的交流! 🦉💬

🚀 技术栈推荐
GoLang, Git, Docker, Kubernetes, CI/CD, Testing, SQL/NoSQL, gRPC, Cloud, Prometheus, ELK Stack

💡 联系与版权声明

📩 联系方式

  • 微信: Libin9iOak
  • 公众号: 猫头虎技术团队

⚠️ 版权声明
本文为原创文章,版权归作者所有。未经许可,禁止转载。更多内容请访问猫头虎的博客首页

点击下方名片,加入猫头虎学习团队。一起探索科技的未来,共同成长。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

猫头虎

一分也是爱,打赏博主成就未来!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值