9

I ran into this error while setting up my Tomcat and Java environmental path:

Neither the JAVA_HOME nor the JRE_HOME environmental variables is defined. At least one of the 2 environmental variables is needed to run this program.

In the user variables: I created JAVA_HOME variables and add C:\Program Files\Java\jdk1.8.0_25 to its path. and then did an edit of system variable PATH, added C:\Program Files\Java\jdk1.8.0_25; to the beginning of the its path. I also created JRE_HOME in user variable and added C:\Program Files\Java\jre1.8.0_25 to its path.

Is it necessary to create JRE_HOME and should I add the JRE path to the system variable also?

Reagan Ochora
  • 1,642
  • 1
  • 19
  • 22
  • 1
    No it is not nessary to add JRE_HOME. Might be Duplicate: http://stackoverflow.com/questions/11120279/difference-between-java-home-and-jre-home – Keen Sage Jan 17 '15 at 05:55
  • side note: You typically add "%JAVA_HOME%/bin" to the path. In your case, there is no reason to add java paths to "path" var. – Jayan Jan 17 '15 at 05:56
  • Kind of similar question is here - https://stackoverflow.com/questions/551668/how-do-i-set-the-default-java-installation-runtime-windows/48690194#48690194 – Betlista Feb 08 '18 at 17:10

4 Answers4

16

This answer explains all the steps with screenshots and examples

Better Use the 8.3 directory-format. In fact No spaces, ever. 8.3 naming

  1. JAVA_HOME - your JDK folder
    C:\Program Files\Java\jdk1.6.0_45 == C:\PROGRA~1\Java\JDK16~1.0_4
    C:\Program Files\Java\jdk1.7.0_71 == C:\PROGRA~1\Java\JDK17~1.0_7
    C:\Program Files\Java\jdk1.8.0_25 == C:\PROGRA~1\Java\JDK18~1.0_2
    C:\Program Files\Java\jdk1.9.0 == C:\PROGRA~1\Java\JDK19~1.0

  2. JRE_HOME
    C:\Program Files\Java\jre6 == C:\PROGRA~1\Java\jre6
    C:\Program Files\Java\jre7 == C:\PROGRA~1\Java\jre7
    C:\Program Files\Java\jre1.8.0_25 == C:\PROGRA~1\Java\JRE18~1.0_2
    C:\Program Files\Java\jre1.9.0 == C:\PROGRA~1\Java\JRE19~1.0

  3. Addition to PATH - best practice!

    • USE WINDOWS+R
    • Enter C:\Windows\system32\systempropertiesadvanced.exe
    • Add ;C:\ProgramData\Oracle\Java\javapath; to the end of PATH
      (System Variables not User Variables).

    • Click OK, explore to C:\ProgramData\Oracle\Java\ and rename javapath folder (from C:\ProgramData\Oracle\Java\javapath\) to javapath_old.

    • Create new folder named javapath.
    • Start CMD and browse into (the now empty) C:\ProgramData\Oracle\Java\javapath\.
    • Run to create symbolic links:

      1. ln -s "C:\Program Files\Java\jre7\bin\java.exe" java.exe
      2. ln -s "C:\Program Files\Java\jre7\bin\javaw.exe" javaw.exe
      3. ln -s "C:\Program Files\Java\jre7\bin\javaws.exe" javaws.exe

    • Done with PATH and *_HOME, now let's continue with the Windows Registry.
  4. Open up you preferred registry editor (Registry Workshop is the best), browse HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit notice all installed versions are shown as keys, double click CurrentVersion (REG_SZ value) and modify its data to your preferred SDK version, mine is 1.7 (For Android Studio) Registry edit

  5. Do the same for HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment (with CurrentVersion) Registry edit

  6. Close down java-based programs such as eclipse or IntelliJ,

    • Open up task-manager- processes tab,
    • Look for explorer.exe, cmd.exe and java(*something*).exe programs,
    • Right-click eache and click End Task (not "End Process-Tree"!)
    • Click FileNew Task➩enter explorer.exe
      .

The changes you've done above were applied successfully
No need to reboot, no need to log-off/on again.

rene
  • 41,474
  • 78
  • 114
  • 152
  • 1
    very good explanation that give interesting shortcuts ( WINDOWS+R, C:\Windows\system32\systempropertiesadvanced.exe...) – Jean-Christophe Blanchard Aug 12 '16 at 09:23
  • 1
    On my Win7 x64 I had no need to touch the registry. But I had to erase the C:\ProgramData\Oracle\Java\javapath\ from the PATH variable and cut/paste the symlinks to somewhere else. – Broken_Window May 31 '17 at 15:46
  • @Jean-ChristopheBlanchard or just press the windows key and type "env" ;) (start menu finds everything easy) – Puddle Feb 10 '22 at 11:41
2

Try this...

For Java,

In the User variables, add PATH value is C:\Program Files\Java\jdk1.8.0_25\bin;

For Tomcat

In the System variables, add JAVA_HOME value is C:\Program Files\Java\jdk1.8.0_25

Now classpath has been set to your machine. You can access java from anywhere in your machine.

After Done this, Go to Command Prompt and go to ApacheTomcat*x.x and move to bin folder,,

Start the Server

startup.bat

For check Tomcat running status, Go to your browser, and Paste the URL,

http://localhost:8080/

Stop the Server

shutdown.bat
Vignesh Shiv
  • 1,129
  • 7
  • 22
2

You really do not need to add JRE_HOME to the system variables. Tomcat looks for JAVA_HOME or JRE_HOME to get itself start. This is because tomcat require some java library to get itself started. Tomcat will provide additional debugging functionality if Jdk is provided instead of Jre. Additional details here

Adding {JAVA_HOME_DIR}/bin to your path would enable to access java from anywhere.

Community
  • 1
  • 1
Keen Sage
  • 1,899
  • 5
  • 26
  • 44
2

After modifying system variables , it is important to open new console window

0xFK
  • 2,433
  • 32
  • 24