Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play framework - how to fix UnsupportedClassVersionError on JRE 6?

I was running my play app on OpenJDK 1.7. All was well and good until I tried to deploy to heroku, which only supports OpenJDK 1.6. I fixed the syntax to run on OpenJDK 1.6, however when I go to run it I get the following error:

erin@bob:/src/playtest$ java -version
java version "1.6.0_23"
OpenJDK Runtime Environment (IcedTea6 1.11pre) (6b23~pre11-0ubuntu1.11.10.2)
OpenJDK 64-Bit Server VM (build 20.0-b11, mixed mode)
erin@bob:/src/playtest$ play run
~        _            _ 
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/   
~
~ play! 1.2.4, http://www.playframework.org
~
~ Ctrl+C to stop
~ 
Listening for transport dt_socket at address: 8000
22:13:21,806 INFO  ~ Starting /src/playtest
22:13:21,811 INFO  ~ Module securesocial is available (/src/play-1.2.4/modules/securesocial-0.2.4)
22:13:21,811 INFO  ~ Module crudsiena is available (/src/playtest/modules/crudsiena-2.0.2)
22:13:21,812 INFO  ~ Module siena is available (/src/playtest/modules/siena-2.0.7)
Exception in thread "main" java.lang.UnsupportedClassVersionError: DocViewerPlugin : Unsupported major.minor version 51.0
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
    at play.classloading.ApplicationClassloader.loadApplicationClass(ApplicationClassloader.java:166)
    at play.classloading.ApplicationClassloader.loadClass(ApplicationClassloader.java:84)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
    at play.plugins.PluginCollection.loadPlugins(PluginCollection.java:158)
    at play.Play.init(Play.java:294)
    at play.server.Server.main(Server.java:158)

It looks like there is a Java 1.7 class compiled somewhere that play is trying to run on the Java 1.6 VM.

I have run play clean, and also deleted the ivy cache and run play deps to reinstall all the dependencies. I have also searched my app directory and my play install directory for stray .class files, and have found none. I also tried clearing /tmp incase a file in there was being referenced, but it had no effect.

DocViewerPlugin is one of the core play plugins and I dont need it, is there any way to blacklist it?

like image 575
Erin Drummond Avatar asked Mar 28 '12 09:03

Erin Drummond


People also ask

How do I fix Java lang UnsupportedClassVersionError in Java?

UnsupportedClassVersionError happens because of a higher JDK during compile time and lower JDK during runtime. How can i make above change? Project -> Properties -> Java Compiler Enable project specific settings. Then select Compiler Compliance Level to 1.7, 1.6 or 1.5, build and test your app.

When my class encounter UnsupportedClassVersionError which option would resolve this issue?

1) If you encounter UnSupportedClassVersionError, check the JRE version you are using to run program and switch to higher version for quick solution.

What is UnsupportedClassVersionError in Java?

Class UnsupportedClassVersionErrorThrown when the Java Virtual Machine attempts to read a class file and determines that the major and minor version numbers in the file are not supported.

How do I fix Java Lang UnsupportedClassVersionError in NetBeans?

You need to call the Java 7 version of the java command. The version used to run NetBeans is set in NetBeans/etc/netbeans. conf. The version used to build and run a project is set by the project properties.


2 Answers

I figured it out. In application.conf, make sure java.source=1.6 is set.

like image 127
Erin Drummond Avatar answered Sep 30 '22 10:09

Erin Drummond


You have to compile the code using the -target 1.6 option.

like image 36
knob creek Avatar answered Sep 30 '22 11:09

knob creek