Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 801
Thorbjørn Ravn Andersen Avatar asked Sep 07 '09 10:09

Thorbjørn Ravn Andersen


People also ask

How do I make JRE my default?

Install latest Sun JDK, e.g. 6u11, in path like c:\install\jdk\sun\6u11 , then let the installer install public JRE in the default place ( c:\program files\blah ). This will setup your default JRE for the majority of things.

How do I change Java to JRE?

In the Java Control Panel, click on the Java tab. Verify that the latest Java Runtime version is enabled by checking the Enabled box. Click OK in Java Control Panel window to confirm changes and close the window. Try to run same applet and verify it is now running using latest version of Java installed in your system.

Why is my Java JRE not JDK?

JDK is the development kit for Java and JRE is the runtime environment. The JDK itself contains the JRE. To run a Java application you need JRE. However, some program needs compiler at runtime so in that case, you need JDK.

What is the default JRE?

default-jre It installs the "Standard Java or Java compatible Runtime", which is OpenJDK 7 JRE. This package points to the Java runtime, or Java compatible runtime recommended for the i386 architecture, which is openjdk-7-jre for i386.


5 Answers

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

like image 168
Dan Rosenstark Avatar answered Sep 27 '22 16:09

Dan Rosenstark


  1. Download JDK from the website
  2. Once everything is finished, go to Control Panel
  3. Open JAVA
  4. Click on the Java tab and select View
  5. There will be one item present in the list. Change the Java Path from JRE to the JDK you downloaded, like so: C:\Program Files\Java\<your_jdk_version>\bin\java.exe.
    For example, mine looks like this: C:\Program Files\Java\jdk1.7.0_07\bin\java.exe
like image 29
charles Avatar answered Sep 27 '22 16:09

charles


Copying the tools.jar file to a location where Eclipse is looking for it may work, but is messy and fragile since that's a step you may not remember the next time you upgrade your JDK. Better is to convince Eclipse to look for it in the proper location.

Setting JAVA_HOME to the correct location works for some tools, but Eclipse does not honor it.

A couple of things to try:

  • Make sure your JDK is identified and selected under Preferences->Java->Installed JREs.

  • Make sure Ant is being invoked by the JDK. One clue is that at the top of the Console output you should see the path of the javaw.exe which is being used. If that path is in the JRE, more convincing is needed. Check Run->External Tools->External Tools Configurations->[your Ant build]->JRE and make sure the settings there point to the JDK.

like image 31
Lyle Avatar answered Sep 30 '22 16:09

Lyle


Try changing the JAVA_HOME environment variable to point to the JDK instead of the JRE.

Alternatively or possibly additionally, add a PATH entry to the JDK bin directory before any of the Windows system directories.

I suspect JAVA_HOME is enough to get Ant working, but it's sometimes nice to get the JDK version of java etc on the path too, so that when you just run java from the command line, you'll get exactly the same version as when you run javac.

like image 32
Jon Skeet Avatar answered Sep 29 '22 16:09

Jon Skeet


You could probably write a WSH script to reconfigure your path automatically.

This JScript script just prints some info:

//file:  jdk.js              usage: cscript /Nologo jdk.js
var objShell = WScript.CreateObject("WScript.Shell");
function setJdk(version) {
  try {
    var jdk = objShell.RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\" +
       "JavaSoft\\Java Development Kit\\" + version + "\\JavaHome");
    if(jdk != null && jdk != "") {
      jdk += "\\bin";
      var path = objShell.RegRead("HKEY_CURRENT_USER\\Environment\\Path");
      path = jdk + ";" + path;
      WScript.Echo("Could set PATH to " + path + "\n");
    }
  } catch(err) { /*probably key does not exist*/ }
}
setJdk("1.7");
setJdk("1.6");
setJdk("1.5");

There is a RegWrite method that can be used to write to the registry. There is a bit of work involved determining the latest version and rejigging the path, removing obsolete entries and sorting out system versus user paths. No doubt it could be used to set JAVA_HOME too. The JDK entry would need to appear before the system32 directory, as the JRE installer puts a java.exe in there.

(I'm not 100% sure if the shell would pick up on such changes or whether a reboot/env variable reload of some kind would be required.)

like image 45
McDowell Avatar answered Sep 27 '22 16:09

McDowell