3

Possible Duplicate:
Java SE 6 vs. JRE 1.6 vs. JDK 1.6 - What do these mean?

I found that sometimes applications ask for java_home to point to a JDK and won't work with a JRE.

Why is that the case? Is it correct?

Community
  • 1
  • 1
user710818
  • 23,228
  • 58
  • 149
  • 207

2 Answers2

6

Short version: some applications use libraries/code that is contained only in the JDK.

Longer version: Usually every Java program should be able to run with just the JRE. And most applications actually work with the JRE.

Now the JDK comes with some additional libraries and tools that you usually only need when developing applications (and not when you simply need to run them).

But occasionally an application decides to use some of the code that gets delivered with the JDK when it runs. It's very rare and is usually not a good idea (unless that application is itself about developing Java applications).

A good example where old versions of Apache Tomcat: it used the Java compiler bundled with the JDK to compile JSP code into bytecode. For this it used tools.jar which is included in the JDK but doesn't get delivered with the JRE.

Newer Tomcats switched to a separate compiler (I think it's based on the Eclipse compiler) for this and no longer require the JDK: they run just fine with just the JRE.

@Rekin mentioned another good example: Maven uses the JDK because it actually compiles Java code.

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • 1
    *"A good example where old versions of Apache Tomcat: it used the Java compiler bundled with the JDK to compile JSP code into bytecode. For this it used `tools.jar` which is included in the JDK but doesn't get delivered with the JRE."* The `tools.jar` is also required for compilation using the [`JavaCompiler`](http://docs.oracle.com/javase/7/docs/api/javax/tools/JavaCompiler.html) of JSE 6+. – Andrew Thompson Nov 26 '12 at 13:41
  • 1
    Right, that's the standardized API for the kind of thing that Tomcat was doing. – Joachim Sauer Nov 26 '12 at 13:45
2

One application I worked on was using the JDK to compile automatically generated java and load it for user after that (a db-oriented compiler/runner).

@Joachim has a more complete answer.

Laur Ivan
  • 4,117
  • 3
  • 38
  • 62