One of the most common problem when using Eclipse to develop web pages (JSPs) is the default JRE settings. By default Eclipse sets the default system JRE as its JRE. This sounds all good, but JSPs require a JDK instead of a JRE - this sounds weird. This article shows you how to solve this very small issue by changing the Eclipse Installed JREs settings.
To avoid confusion in this article, I'm going to use italics to refer to the JRE Eclipse name (nothing to do with Java unless otherwise told), that is, the name Eclipse uses and has nothing to do with the Java JRE. Also, JDK means Java Development Kit and JRE (not in italics) means Java Runtime Environment.
Set Eclipse Installed JREs
Check your JDK
Before you proceed, make sure that you have a JDK installed. You can do so by executing the following command on your command prompt.
C:\>javac -version javac 1.6.0_02
In my case I have a copy of Java 1.6 update 2 installed. Your version may be different from the one displayed above, depending on the version you have installed. As long as the above command returns something (similar to the above) it's OK. If the above returns an error similar to following, it means that either you don't have a JDK installed or the JDK bin directory is not in your system path.
C:\>javac -version 'javac' is not recognized as an internal or external command, operable program or batch file.
In this case, browse to the folder where you think Java is installed (on Windows this is usually:
C:\Program Files\Java or
C:\Program Files (86)\Java in case of 64 bit Windows version) and check it yourself. Alternatively, visit Sun's website (http://java.sun.com) and download and install the JDK from there. Make sure to download the JDK and not the JRE.
Set the Installed JREs
Open Eclipse if it is not already running. Open the Preferences from the Windows menu as shown below.
Expand the Java node and select the Installed JREs sub-node.
JSPs require that Eclipse default Installed JRE is actually pointing to a JDK and not a JRE. Thus if your default Installed JRE is pointing to a JRE instead, you need to replace it with your JDK. This may sound weird since the dialog is asking you for a JRE.
The process is very simple:
- First add a new JRE by clicking the Add button. You cannot just remove your only JRE without first adding another JRE.
- Select Standard VM option from the list and click Next.
- Click the Directory button or manually enter the path to your (latest or which one you require) JDK directory on your local machine. Note that the JDK directory is the folder where JDK was installed. See the next screen shot.
- Wait for Eclipse to verify your entry and list the libraries.
- Optionally, you can change the JRE name to a name of your liking.
- Click Finish to complete the process.
- Set the new JRE (that is, the JDK just added) as your default JRE by checking the checkbox near the JRE friendly name (usually the first column).
- Optionally, you can remove the other JRE by first selecting it (not setting it as your default) and pressing the Remove button.
- Click OK to close the preferences dialog.
With the default JRE set to a JDK, test your JSPs and confirm that the errors are now gone and the JSPs are now compiling.