gonfi dentschal
gonfi dentschal

Reputation: 121

tomcat7 UnsupportedClassVersionError when running with java7

problem: when deploying my war to tomcat7 i get the error java.lang.UnsupportedClassVersionError: org.MyLibraryClass : Unsupported major.minor version 51.0

(this is the error one gets when compiling java with a newer version than the java used when running the code.)

situation, in order:

  1. brand new ubuntu 12.04.1 server 64bit minimal, in a virtualbox
  2. installed tomcat6
  3. tried to deploy my war
  4. realized the error, and that i need java7 because ubuntu 12 still comes with outdated java
  5. installed oracle java 7 using this guide https://askubuntu.com/questions/197248/java-on-ubuntu-server-12-04

      sudo add-apt-repository ppa:webupd8team/java
      sudo apt-get update
      sudo apt-get install oracle-java7-installer
    
  6. removed tomcat6 and installed tomcat7

      sudo apt-get remove tomcat6-common
      sudo apt-get install tomcat7
    
  7. deployed my war to tomcat7

  8. started tomcat

      sudo service tomcat7 start
    
  9. checked my app's log file. same error.

  10. echo $JAVA_HOME is empty, java -version shows:

      java version "1.7.0_07"
      Java(TM) SE Runtime Environment (build 1.7.0_07-b10)
      Java HotSpot(TM) 64-Bit Server VM (build 23.3-b01, mixed mode)
    
  11. it's a default tomcat7 install, no modification. still i checked the startup scripts and config to make sure no custom java version is specified anywhere. also checked by asking catalina:

  ubuntu@ubuntu:/home$ /usr/share/tomcat7/bin/catalina.sh version
  Using CATALINA_BASE:   /usr/share/tomcat7
  Using CATALINA_HOME:   /usr/share/tomcat7
  Using CATALINA_TMPDIR: /usr/share/tomcat7/temp
  Using JRE_HOME:        /usr
  Using CLASSPATH:       /usr/share/tomcat7/bin/bootstrap.jar:/usr/share/tomcat7/bin/tomcat-juli.jar
  Server version: Apache Tomcat/7.0.26
  Server built:   Jul 19 2012 03:21:30
  Server number:  7.0.26.0
  OS Name:        Linux
  OS Version:     3.2.0-29-generic
  Architecture:   amd64
  JVM Version:    1.7.0_07-b10
  JVM Vendor:     Oracle Corporation

now i'm stuck. i don't see how any java code could fail to run on oracle's jre7.

my war is a brand new very basic hello world grails 2.1 app with maven, which has a maven dependency (org.MyLibraryClass) that is compiled with jdk7. that's the one for which i get the error.

in grails i changed BuildConfig.groovy to have 1.7 instead of 1.6:

  grails.project.target.level = 1.7
  grails.project.source.level = 1.7

then did a grails clean, rebuild, war, redeploy. no change.

any idea what to try next?

Upvotes: 0

Views: 629

Answers (3)

tinylee
tinylee

Reputation: 5174

I have the same problem just now,but now it's solved.

Please check this symbolic

/usr/lib/jvm/default-java

it's default link is open-jdk, reset the correct jdk dirctory.

good luck!

Upvotes: 0

Michael Amthor
Michael Amthor

Reputation: 123

Typical error when compiling code with Java7 and running it under Java6.

Upvotes: 1

unixrules
unixrules

Reputation: 608

The critical line in your query is this one I think:

sudo service tomcat7 start

I think it may be triggering the inheritance of OpenJDK still in the system there. What you want to do is instead try tomcat from your own environment.

Login as your normal user

java -version
/usr/share/tomcat7/bin/startup.sh

and check. You should also login as a clean user, root or elsewhere and check java -version to check.

If all else fails, go to /etc/profile and make sure path to Oracle's Java/bin directory is the very first thing in the PATH variable for the environment.

Upvotes: 0

Related Questions