Forum Stats

  • 3,758,931 Users
  • 2,251,475 Discussions
  • 7,870,440 Comments

Discussions

sqlcl java errors under different db homes

Jeff Chirco
Jeff Chirco Member Posts: 166 Blue Ribbon
edited Apr 1, 2019 12:42PM in SQLcl

I am running version 4.2.0 of SQLcl on my Linux machine and it works find when my Oracle Home is set to a 12.2 instance. But when I set it to a 12.1.0.2 instance I get the following errors. How come? How do I fix this?                                            

Exception in thread "main" java.lang.UnsupportedClassVersionError: oracle/dbtools/raptor/scriptrunner/cmdline/SqlCli : 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)

Could not find the main class: oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.  Program will exit.

Patrick Bacon

Answers

  • Gary Graham-Oracle
    Gary Graham-Oracle Member Posts: 3,256 Bronze Crown
    edited Apr 26, 2017 7:18PM

    From what I have read, this means you are trying to launch a Java application compiled with a 1.7 JDK using a JRE of 1.6 or lower.  So check your 12.1.0.2 environment and to see what java version you are pointing to, and fix it to point at a JRE of 1.8 (which SQLcl 4.2.0 requires).

  • Jeff Chirco
    Jeff Chirco Member Posts: 166 Blue Ribbon
    edited Apr 26, 2017 7:20PM

    When I run java -version I get:

    openjdk version "1.8.0_131"

    OpenJDK Runtime Environment (build 1.8.0_131-b11)

    OpenJDK 64-Bit Server VM (build 25.131-b11, mixed mode)

  • Gary Graham-Oracle
    Gary Graham-Oracle Member Posts: 3,256 Bronze Crown
    edited Apr 28, 2017 7:23PM
    When I run java -version I get:

    I would not rely on java -version to see which java SQLcl actually uses.  For example, in my Windows 7 environment...

    C:\Tools\sqlcl\420\sqlcl\bin>echo %JAVA_HOME%C:\Program Files\Java\jdk1.8.0_121C:\Tools\sqlcl\420\sqlcl\bin>java -versionjava version "1.8.0_121"Java(TM) SE Runtime Environment (build 1.8.0_121-b13)Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)C:\Tools\sqlcl\420\sqlcl\bin>sql hr/[email protected]: Release 4.2.0 Production on Fri Apr 28 16:07:08 2017Copyright (c) 1982, 2017, Oracle.  All rights reserved.Connected to:Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit ProductionSQL> show javaJava Detail-----------java.home= C:\Program Files\Java\jdk1.8.0_131\jrejava.vendor= Oracle Corporationjava.vendor.url= http://java.oracle.com/java.version= 1.8.0_131--------------------------------------------------------------------------------os.arch= amd64os.name= Windows 7os.version= 6.1path.separator= ;file.separator= \line.separator=user.dir= C:\Tools\sqlcl\420\sqlcl\binuser.home= C:\Users\gggraham.ORADEVuser.name= gggraham----------------------------------------------------------------------------------------------------------------------------------------------------------------SQL>

    So I get 1.8.0_131 despite pointing the JAVA_HOME at 1.8.0_121.  Not exactly sure how SQLcl picks the JDK, or if passing the -verbose parameter when starting it (e.g, sql -verbose -noupdates <user>/<pw>@SID)  will help give you any clues.

  • Jeff Chirco
    Jeff Chirco Member Posts: 166 Blue Ribbon
    edited May 8, 2017 6:16PM

    I can't even launch sqlcl so not sure how i am supposed to check the version of java from sqlcl

    ./sql

    Exception in thread "main" java.lang.UnsupportedClassVersionError: oracle/dbtools/raptor/scriptrunner/cmdline/SqlCli : 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)

    Could not find the main class: oracle.dbtools.raptor.scriptrunner.cmdline.SqlCli.  Program will exit.

  • Gary Graham-Oracle
    Gary Graham-Oracle Member Posts: 3,256 Bronze Crown
    edited May 8, 2017 10:19PM

    I looked into this a bit more.  Regarding my prior, vague Windows comments, this is a more complete desription of how it actually works...

    1. If a JRE is copied into a sqlcl\jre folder, then SQLcl uses that Java version.

    2. Otherwise, running sql.bat uses an explicitly set JAVA_HOME, followed by the Java version appearing first in PATH.

    3. Otherwise, running sql.exe first checks the Windows Registry for which Java version to use, then falls through to the rules in (2).

    And, as previously noted, the Java version must be at least 1.7 to avoid an Unsupported major.minor version error.

    On Linux (see the sqlcl/bin/sql script), the rules are a bit different...

    1. If a JRE is copied into a sqlcl/jre folder, then SQLcl uses that Java version.

    2. Otherwise it uses the Java version specified in JAVA_HOME.

    3. Otherwise it uses the Java version from the current ORACLE_HOME

    4. Otherwise it uses the Java version appearing first in PATH.

    Patrick Bacon
  • Jeff Chirco
    Jeff Chirco Member Posts: 166 Blue Ribbon
    edited May 9, 2017 10:23AM

    Thanks for the reply Gary. 

    I am running this on Linux. 

    1. I don't have a sqlcl/jr folder
    2. My JAVA_HOME was not set
    3. So I guess it was using the Java version from ORACLE_HOME which was a 12.1.0.2 install

    I ended up setting JAVA_HOME to my jdk folder of my 12.2.0.1 install and that worked. But not sure if this is the best thing to do.

  • Gary Graham-Oracle
    Gary Graham-Oracle Member Posts: 3,256 Bronze Crown
    edited May 9, 2017 12:42PM

    It looks like the developer's well-intentioned idea to pick up the jdk from ORACLE_HOME tripped you up (me too, since I checked on Windows and did not read the bash script until later).  Now, at least, anyone who reads this (or the script) will understand how it works.

    Setting JAVA_HOME is probably the most commonly used, and simplest, approach. 

  • Fernando J. Andrade
    Fernando J. Andrade Member Posts: 3 Red Ribbon
    edited Mar 31, 2019 11:35AM

    I think the problem is with this code in the first lines of sql  bash script.

    If the ORACLE_HOME is set it always points to the ORACLE_HOME java.

    #

    # if we are in ADE environement, check for JAVA_HOME

    #

    function checkADE {

            #

            # Resolve java path for development builds

            #

           if  [  "m$ORACLE_HOME" != "m" ]; then

             if  [ -d "$ORACLE_HOME/jdk/jre" ]; then

                 JAVA_HOME=$ORACLE_HOME/jdk/jre

                 PATH=$JAVA_HOME/bin:$PATH

             fi

             export SQLPLUS_CLASSIC=true

           fi

    }

    unset the oracle home prior launching sql or edit this part of the script.

    FJA

  • Glen Conway
    Glen Conway Member Posts: 859 Gold Badge
    edited Apr 1, 2019 12:28PM

    Changing the script is always an option, of course, but I guess the goal of the other posters was to launch SQLcl by only adjusting environment variables.

    Actually I am surprised that you were able to update this discussion after a near two-year delay -- I thought these things get archived after a few months.

  • Fernando J. Andrade
    Fernando J. Andrade Member Posts: 3 Red Ribbon
    edited Apr 1, 2019 12:42PM

    Well I faced the same problem yesterday. I was searching for a post on how to solve it. Found nothing but this post so I decided to update it.

    I think the problem is that if you want to use sqlcl on a server with the database on it, the ORACLE_HOME will be there, and therefore that function will force the use of the jre on the ORACLE_HOME. If you use 12.1, the sqlcl won´t work.

    There are two options: unset the ORACLE_HOME and launch sqlcl or edit the bash script for sqlcl and comment the function that forces the use of the jre on the ORACLE_HOME.

    For me the option that edits the code was the better so I can still connect directly to the database using sqlcl only setting the ORACLE_SID.

    FJA