Search code examples
javawindowsantjavac

How do I make the JDK the default JRE?


I use Eclipse with ant scripts, and Eclipse works well with the default JRE installation on Windows XP.

The annoyance comes when I want to run ant scripts compiling with the javac-tag, where it fails because there is no tools.jar in the classpath.

I've gotten the idea that if I could make the JDK become the default Java on Windows, then I would have what I have today, plus ant working out of the box.

Can this be done? What have I missed in the installation process?


Edit: I know of JAVA_HOME, but that is tedious and error prone (manually updating environment variables when a fresher JDK is available is not always something I remember).


Edit: I ended up figuring out how to make the javac task use the Eclipse compiler (ecj.jar), which works very nicely.


Edit: Maven also supports using the Eclipse compiler, but this appears to be very rarely used and with an old version of ecj.jar. I intend to look in to this at a later time.


Edit: Using ecj with maven-compiler-plugin 3.0 works very well, and allows for building with a JRE.


Edit: I had problems with the javadoc tool crashing when parsing bytecode generated by ecj.


Solution

  • The answer is "no," there is no way to get the JDK to be the default JVM upon install.

    As the other answers point out, you can adjust your path and your JAVA_HOME to point to the JDK, or a different JVM entirely. This is in fact what the Java installation does in the first place.

    However, your problem is that you want tools.jar to be found. To do this you can copy it to the ext directory under your default JVM. Check the JDK file structure here. This will probably work.

    On the other hand, if modifying the JAVA_HOME and PATH variables for Java seems annoying, remember that it's just one of a series of things we do to keep us sharp just kidding, sucks that we still have to do this in 2009