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.
Worked perfectly, once I figured out that the install for jdk 1.6_16 was referencing the C:\Program Files\Java\jdk1.6.0_16 and not the install directory I had told the sun jdk installer to work in, which was C:\java\jdk_1_6_16. That was just the jre.
ReplyDeleteHope this helped.
Thnx for the post Albert.
ReplyDeleteYou have helped me a lot....
Thanks for this! I was stuck because my jsps wouldn't compile but your post helped me resolve the error.
ReplyDeleteThanks a lot, you saved my day (or actually my night).
ReplyDeleteWas stuck trying out a jsp tutorial and was getting very frustrated.
You have my heartfelt thanks :)
Very helpful information. Thank you.
ReplyDeletevery helpful thanks a lot....
ReplyDeleteThank you!!Thank you!!Thank you!!
ReplyDeleteVery helpful. You saved me a ton of time.
ReplyDeletethanks dude. java is screwed up sometimes. they know this..why dont they handle it?
ReplyDeleteThanks a lot!! <3
ReplyDeleteHi Albert Attard !
ReplyDeleteThanks for your information, i have resolved my issue in eclispe.
Keep on growing ....
---------
Thangavel L Nathan...
Thanks for the detailed post. This was a tailor-made solution.
ReplyDeleteThank you big time
ReplyDeleteThanks a lot!!!!
ReplyDeleteMany thanks for the solution and clear explanation!
ReplyDeletethanks:)
ReplyDeletethanks!
ReplyDeletevery very helpfull...
Absolutely heartfelt thanks! You saved my teams hours of work and refactoring!
ReplyDeletevery helpful, however in my case I had to do something else:
ReplyDeletepreferences->java->installed jres->execution environments
there I had to select the jdk. then it worked perfectly!
Very helpful. Thanks!
ReplyDeleteThank you!!!!!!! I could not do it without this page!!! :)
ReplyDeleteI thot I knew what to do, but could do it only after reading your post.
ReplyDeleteplz give the exceat link for jdk version i cant identified.
ReplyDeleteDo you have a JDK installed?
ReplyDeleteYou can download the latest version from: http://www.oracle.com/technetwork/java/javase/downloads/java-se-jdk-7-download-432154.html.
Netbeans vet new to Eclipse. Worked like a charm! Thanks.
ReplyDeletegreat post, thanks
ReplyDeletework like charm
ReplyDeleteThanks
thanks very much , i've been messed up this error since a whole day !
ReplyDeleteIt works only for me, if i do a full rebuild, what should i do?
ReplyDeleteNow when using JDK1.7 I get the error as below. Could not even run it locally as prior to this update I could do that with no problem.
ReplyDeleteWARNING: EXCEPTION
java.lang.ClassNotFoundException: guestbook.GuestbookServlet