3

Machine has JDK/JRE 8 but it is still pointing to JDK 1.6

I have Java 8 (JDK and JRE 8) on my machine. I have Eclipse Mars 4.5.1 . I am trying to create a simple Static Web Project and while running the project on HTTP Preview (or a Dynamic Web Project on Apache Tomcat for that matter), it gives the following error. (Also see the screenshot attached.)

Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/jetty/server/Handler : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

Gaurav51289
  • 540
  • 2
  • 7
  • 16
  • 1
    This might be useful to set default JDK from multiple installed JDKs : http://stackoverflow.com/questions/21964709/how-to-set-or-change-the-default-java-jdk-version-on-os-x – Maulik Feb 18 '16 at 12:01

1 Answers1

1

The problem is that you're using JDK1.8 to compile your code (with target runtime of 1.8).

However, your server is configured to run with JDK 1.6 (you can see it at the top of the console window [ HTTP preview at...])

Change your workspace default JRE to your JDK 1.8 if you want to use the http preview (I tried and saw no option to specify a runtime JRE).

If you want to use tomcat, then specify the correct JRE on the first page of the 'New Server' wizard.

ernest_k
  • 44,416
  • 5
  • 53
  • 99
  • Thanks..!! It is working for Tomcat with Java 8. Is there no solution for HTTP Preview. Because I am using the similar configs for my windows machine and everything is working fine with Java 8. – Gaurav51289 Feb 18 '16 at 09:45
  • 1
    Perhaps the difference is workspace-related. How many 'Installed JREs' do you have in the current workspace? Can you try trimming the list to 1 (of course, keeping 1.8) or making 1.8 the default runtime? Not sure whether a restart of eclipse will be necessary. – ernest_k Feb 18 '16 at 09:51