Error when starting Tomcat, unsupported major/minor version, environment variables seem correct though

40,718

Solution 1

Open tomcat/bin directory and change JAVA_HOME parmater in catalina.sh

Solution 2

I dont think that given responses are correct. In fact, major.minor exception means that the current Java version you have installed does not match the minimum requirement. In particular, in your error says 51 (which is the internal code for Java SE 7). So to fix the issue you actually need to install Java 7.

Solution 3

Ensure the JRE_HOME is set to JRE1.6 (or greater).

Also, just a gotcha. If you have two installations of Tomcat (i.e. Tomcat8 alongside Tomcat7), make sure your CATALINA_HOME variable isn't set to the Tomcat8's path. As this will also cause this issue. (I overlooked the logs at first!)

C:\devtools\apache-tomcat-7.0.47\bin>set CATALINA_HOME=C:\devtools\apache-tomcat-8.0.0-RC5

C:\devtools\apache-tomcat-7.0.47\bin>configtest.bat
Using CATALINA_BASE:   "C:\devtools\apache-tomcat-8.0.0-RC5"
Using CATALINA_HOME:   "C:\devtools\apache-tomcat-8.0.0-RC5"
Using CATALINA_TMPDIR: "C:\devtools\apache-tomcat-8.0.0-RC5\temp"
Using JRE_HOME:        "C:\Progra~1\Java\jdk1.6.0_45\jre\"
Using CLASSPATH:       "C:\devtools\apache-tomcat-8.0.0-RC5\bin\bootstrap.jar;C:\devtools\apache-tomcat-8.0.0-RC5\bin\tomcat-juli.jar"
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/catalina/startup/Bootstrap : Unsupported major.minor version 51.0
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        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)
Could not find the main class: org.apache.catalina.startup.Bootstrap.  Program will exit.

Fyi, you can unset CATALINA_HOME by using:

set CATALINA_HOME=
Share:
40,718
Maltiriel
Author by

Maltiriel

I'm a full time software developer with an MS in CS and a BS in CS and Math. I've worked in Java, javascript, html, CSS, Perl, C, Fortran, C++ and most lately Flex and Ruby.

Updated on August 29, 2022

Comments

  • Maltiriel
    Maltiriel over 1 year

    I'm having a problem starting Tomcat 7 from the command line on Linux, and the log shows this:

    Sep 24, 2012 8:54:10 AM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the jav
    a.library.path: /usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/lib/amd64/server:/usr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/lib/amd64:/u
    sr/lib64/jvm/java-1.6.0-openjdk-1.6.0/jre/../lib/amd64:/usr/lib64/mpi/gcc/openmpi/lib64:/usr/java/packages/lib/amd64:/usr/lib64:/lib6
    4:/lib:/usr/lib
    Sep 24, 2012 8:54:10 AM org.apache.tomcat.util.digester.Digester startElement
    SEVERE: Begin event threw error
    java.lang.UnsupportedClassVersionError: pms/security/BCryptRealm : Unsupported major.minor version 51.0
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:634)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:277)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:73)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:212)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
            at org.apache.tomcat.util.digester.ObjectCreateRule.begin(ObjectCreateRule.java:144)
            at org.apache.tomcat.util.digester.Digester.startElement(Digester.java:1276)
            at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:504)
            at com.sun.org.apache.xerces.internal.parsers.AbstractXMLDocumentParser.emptyElement(AbstractXMLDocumentParser.java:182)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(XMLDocumentFragmentScannerImpl.jav
    a:1320)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScann
    erImpl.java:2732)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:625)
            at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:48
    8)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:819)
            at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:748)
            at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:123)
            at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1208)
            at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:525)
            at org.apache.tomcat.util.digester.Digester.parse(Digester.java:1537)
            at org.apache.catalina.startup.Catalina.load(Catalina.java:610)
            at org.apache.catalina.startup.Catalina.load(Catalina.java:658)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:616)
            at org.apache.catalina.startup.Bootstrap.load(Bootstrap.java:281)
            at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:450)

    From googling I understand the first bit I can just ignore, but I was wondering if that's indicative of the version of Java it's trying to use, since it keeps saying Java 6. The "Unsupported major.minor version 51.0" I understand means I have a problem with Java versions somehow.

    I built the class it's having problems with (a custom realm to use BCrypt) using ant, and running ant -v shows it's compiling with Java 7, which is what I want. I've set JAVA_HOME and JDK_HOME to use Java 7 as well (they're all pointing to the same place as far as I can tell).

    What else am I missing? If more info is needed let me know. I'd really appreciate any pointers on where I should look for whatever is going wrong. Thanks.

    ETA a little more info per questions in comments: I'm starting tomcat via the command line. I just do ./bin/startup.sh from the tomcat base directory. I downloaded tomcat from the Apache website. I got the core tar.gz version and unpacked it just last night (I only had version 6 before and wanted to upgrade). Also this isn't my personal machine; I only have user rights, if that matters.

  • Maltiriel
    Maltiriel over 11 years
    Where in that file would I set JAVA_HOME? Just at the end of it?
  • Ilya
    Ilya over 11 years
    At begin of it. JAVA_HOME="/usr/share/..." or witch path you have
  • Maltiriel
    Maltiriel over 11 years
    Huh. Setting JAVA_HOME didn't work but setting JRE_HOME did. Thanks!
  • Maltiriel
    Maltiriel over 10 years
    Java 7 was most definitely installed on the machine; I even said in my question that I had compiled code with Java 7 on that machine (and verified via ant -v that it was in fact using Java 7 to compile). It simply wasn't actually being used to run Tomcat. Then there's the fact that I followed the steps given in the accepted answer and got it to work. I did NOT have to install Java 7 as it was already there, and I only had user permissions anyway so I couldn't have done that even if I wanted to.
  • juancancela
    juancancela over 10 years
    Before downvoting my answer, you could comment first, at least. I DO said that the error you got means what i said that it means. You can see, for example, this answer: stackoverflow.com/questions/10382929/… (incredibly upvoted, you see?) that basically says the SAME thing i told you, but with more detail.
  • Maltiriel
    Maltiriel over 10 years
    Trying to follow your answer would not have solved my problem at all. Java 7 was already installed. I needed help with how to tell Tomcat to run using a different version of Java from what it was using by default. Your answer didn't address that at all.
  • Hoàng Long
    Hoàng Long about 8 years
    When I check the code, Tomcat only uses JAVA_HOME if it is debug. Otherwise it uses JRE.