133

I pointed the JAVA_HOME to C:\Program Files (x86)\Java\jre7. It works fine. Afterwards, I unzipped ant and set up the environment variables related to Ant, I got the following error messages after typing "ant -version"

image

I searched this forum. Looks like one solution is to point Java to JDK instead of JRE. I am not exactly sure whether this should be the solution. In other words, in general, which one should JAVA_HOME point to? JDK or JRE?

Arya Pourtabatabaie
  • 705
  • 2
  • 7
  • 22
user297850
  • 7,705
  • 17
  • 54
  • 76

8 Answers8

143

If you're doing any sort of development, or building with Maven or Ant, you need to point to the JDK (Java Development Kit) where utilities such as javac (the Java Compiler) reside. Otherwise, you can point to the JRE (Java Runtime Environment).

The JDK contains everything the JRE has and more. If you're just executing Java programs, you can point to either the JRE or the JDK.

David W.
  • 105,218
  • 39
  • 216
  • 337
  • 9
    So `JAVA_HOME` is used to do two things: 1: for development tools, finding `javac.exe`. 2: for nondevelopment tools, finding `java.exe`. This seems to violate ["one tool for one thing"](https://en.wikipedia.org/wiki/Unix_philosophy#Doug_McIlroy_on_Unix_programming). Shouldn't `JDK_HOME` be used instead? – Pacerier Sep 14 '15 at 06:24
  • 5
    Diagram on this site shows the relationship between JDK and JRE. https://docs.oracle.com/javase/8/docs/ – andrybak Apr 13 '17 at 11:19
  • 1
    Is it possible to validate pro-grammatically whether the Java path is set as JRE or JDK? – Dinesh Kumar P Mar 02 '18 at 11:22
  • 1
    So it has to point to the `bin` directory where `javac` resides? – Superdooperhero Dec 10 '20 at 11:21
  • Confusingly (for me at least), this meant setting it to /usr when I wanted it to find the javac at /usr/bin/javac, so you need the directory outside the bin directory that contains your jdk executables. – combinatorist Jan 09 '23 at 18:49
16

Simply (change to your jdk1.x.x.x_xx)

JAVA_HOME=C:\Program Files\Java\jdk1.8.0_05

Amr Lotfy
  • 2,937
  • 5
  • 36
  • 56
6

My JAVA_HOME points to the JDK. If it still doesn't work, check if you downloaded ant for Java 7 and not for Java 6.

Francois Bourgeois
  • 3,650
  • 5
  • 30
  • 41
das_j
  • 4,444
  • 5
  • 31
  • 47
5

Generally, it does not matter if you point it at JRE or JDK. It depends on the application which uses it. Ant documentation says you should point it at JDK to get all Ant's features.

Jan Martiška
  • 1,151
  • 5
  • 7
3

as a developer, you should point your JAVA_HOME at jdk to access javac copiler etc. It's good if you can test your program to run on the JRE though. If you are using an app server you often also need the JDK instead of the JRE but that depends on the particular server.

akostadinov
  • 17,364
  • 6
  • 77
  • 85
3

You can use either the JDK or the JRE but:

JAVA_HOME is used by the launcher for finding the JDK/JRE to use. (JDK is recommended as some tasks require the java tools.)
. ANT_HOME setting
michaelok
  • 1,124
  • 1
  • 13
  • 20
3

For people late to the party and learning it now, it doesn't matter now since new JDK versions don't have separate JRE folder. So, we can point to JDK and be done with it.

Sarth
  • 266
  • 2
  • 5
0

Let's keep it simple. Go to settings and search "Environment Variables". Once environment variables window pops up, simply create a new SYSTEM variable by clicking on NEW and then BROWSE DIRECTORY until you locate the install path of the JDK. The JDK should be installed in program files and you will see a JAVA folder and inside the folder is JDK and JRE... If you write code you must select JDK!!! Do not listen to anyone stating JRE will suffice... NO! It will NOT! The proper directory should look like this C:\Program Files\Java\jdk1.8.0_144 it's as simple as that!

nexogen.io
  • 51
  • 2
  • 3
    @Stephan The existing answers already provide the information I took the time to provide. That is your justification for downvoting? This is the problem with many of these threads. For one, just because the basic principle was answered doesn’t mean the answer was well formed or even helpful. My answer is not at all the same as the previous responses. The answer I provided, came with precise instructions – nexogen.io Oct 26 '18 at 11:57