9

I'm trying to run a parser built in Java, but every time I try to use the class, I get the above error ("Exception in thread "main" java.lang.UnsupportedClassVersionError: danbikel/parser/Trainer (Unsupported major.minor version 50.0)").

From what I've read, this may be a problem with a mismatch between the versions of Java used to compile and run the code; but I've made sure that my JAVA_HOME environment is set to version 1.6, which is the version recommended by the parser's installation guide.

There are older versions of Java installed on the server, but I can't do anything about that. Is there anything else I can do about this error?

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
Caitlin
  • 91
  • 1
  • 1
  • 2
  • possible duplicate of [How to fix: Unsupported major.minor version 51.0 error?](http://stackoverflow.com/questions/10382929/how-to-fix-unsupported-major-minor-version-51-0-error) – kenorb Apr 04 '15 at 12:03

6 Answers6

8

Use sudo update-alternatives --config java and set the version you may want to use if you are using a Debian-derived distro (such as Ubuntu).

Venugopal Madathil
  • 2,031
  • 3
  • 34
  • 44
5

Aside from setting JAVA_HOME appropriately (which you've done), ensure that you're executing the right version of the java executable. e.g., on Debian or Ubuntu, execute /usr/lib/jvm/java-6-openjdk/jre/bin/java directly, if /usr/bin/java points to the wrong version.

You can use the -version option to verify the version of the launcher you're using. Try java -version and /usr/lib/jvm/java-6-openjdk/jre/bin/java -version and see if the output is any different.

C. K. Young
  • 219,335
  • 46
  • 382
  • 435
  • Thanks; the problem might be that /usr/bin/java is pointing to the wrong version. All of the programs in this parser are run from shell scripts. I'll see if they're launching the wrong version of java. – Caitlin Mar 30 '11 at 05:00
  • You can also use the System property "java.version" at runtime to tell what's running. See this page under the "getProperties" javadocs to see what properties are available to you at runtime: http://docs.oracle.com/javase/6/docs/api/java/lang/System.html – Matt Jul 23 '12 at 12:32
4

Making sure that JAVA_HOME is set to a particular Java installation is not necessarily enough.

If you have more information on your server and the configuration environment used it would be helpful.

I would make sure that your PATH environment includes ${JAVA_HOME}/bin:${PATH} if you want to make absolutely sure you are using the correct version.

kenorb
  • 155,785
  • 88
  • 678
  • 743
Dave G
  • 9,639
  • 36
  • 41
3

It is likely that your java veriosn is still 1.5 even if you have set JAVA_HOME to 1.6

Type java -version on the console and see what version it prints.

Rahul
  • 12,886
  • 13
  • 57
  • 62
0

I also had this problem and I resolved it after I found that I had set a custom JAVA_HOME value in my .bash_profile.

I commented this out, loaded a new console and now my project builds.

IanGSY
  • 3,664
  • 1
  • 22
  • 40
0

For me this worked: 1) install JRE 7 2) Install JDK 3) Go to Project Properties>Java Compiler. Set Compiler Compliance level to 1.7.Once you press 'Apply', it would ask you to rebuild the program. For most people that should do it. For the rest, see a warning section(marked with an yellow '!' mark) appears at the bottom of the Properties window, where it asks to search for the compatible JRE. Choose either to configure installed JREs or set your environment variable. Once you are done, you are good to go!