10 Replies Latest reply on Nov 16, 2018 8:06 PM by Glen Conway

    SQLCL Java Error

    dba_chad

      Greetings,

       

      I'm attempting to get SQLCL working on our REL servers.  I've copied a Java 1.8 JRE into a folder under my sqlcl directory:

       

      /home/user/sqlcl/jre

       

      I've even set my JAVA_HOME and even added it to PATH:

       

      JAVA_HOME=/home/user/sqlcl/jre/bin

      PATH=/usr/share/centrifydc/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/sqlcl/bin:/home/user/sqlcl/jre/bin

       

      I'm still receive the following when invoking sqlcl:

       

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

       

      # which java

      ~/sqlcl/jre/bin/java

       

      # java -version

      java version "1.8.0_91"

      Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

      Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

       

      This setup works on a REL7 machine, but not on REL6.

        • 1. Re: SQLCL Java Error

          Well that is the classic exception you get when you use a Java version that is LOWER than the code you are trying to execute.

          I've even set my JAVA_HOME and even added it to PATH:

          Except you added them to the END of the path.

           

          And that means that the previous path components will be searched first and any match found will be executed. So somewhere

           

          I suggest you follow the standard practice of using scripts (batch files) to set up the environment you need when you want to execute an application.

           

          That allows you to control the components you will use.

           

          If you do add to a system environment variable (e.g. PATH) you need to add to the FRONT so that it will be the FIRST thing found.

          • 2. Re: SQLCL Java Error
            dba_chad

            I adjusted my PATH; however, I'm still getting the same error:

             

            # echo $PATH

            /home/user/sqlcl/jre/bin:/usr/share/centrifydc/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/user/sqlcl/bin

             

            # which java

            ~/sqlcl/jre/bin/java

             

            # java -version

            java version "1.8.0_91"

            Java(TM) SE Runtime Environment (build 1.8.0_91-b14)

            Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

             

            # which sqlcl

            ~/sqlcl/bin/sqlcl

             

            # sqlcl

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

             

            It's odd as on a REL7 server, which is where the JRE originally came from, SQLCL appears to do as the documentation states which is to look for and use first the jre under its sqlcl directory first. 

             

            Do I actually need to have Java1.8 installed on the REL6 servers or can I use a 1.8 JRE from a different server to get this to function?

            • 3. Re: SQLCL Java Error

              Do I actually need to have Java1.8 installed on the REL6 servers or can I use a 1.8 JRE from a different server to get this to function?

              Sql Developer itself requires a JDK not just the JRE.

               

              Not sure about the command-line tool. Try using the proper JDK for the sql dev version you are using and see if that helps.

              • 4. Re: SQLCL Java Error
                thatJeffSmith-Oracle

                JRE is all we need for SQLcl

                • 5. Re: SQLCL Java Error
                  dba_chad

                  Will a JRE from a REL7 box work on REL6?  The box itself only has Java 1.7 on it however the JRE is from 1.8

                  • 6. Re: SQLCL Java Error
                    dba_chad

                    I downloaded a new JRE from the java site.  Along with that I removed the jre directory under my sqlcl directory and set JAVA_HOME to be the location of this downloaded JRE.  I'm still getting the same error of:

                     

                    Exception in thread "main" java.lang.UnsupportedClassVersionError: oracle/dbtools/raptor/scriptrunner/cmdline/SqlCli : Unsupported major.minor version 52.0

                     

                    Isn't version 52.0 the equivalent of java 1.8 and isn't this the required version for SQLCL 18.3 ?  Is there any other debugging I can do during my call to sqlcl to get more detailed error information?

                    • 7. Re: SQLCL Java Error
                      Glen Conway

                      According to https://en.wikipedia.org/wiki/Java_class_file the major.minor version 52.0 refers to Java 8:

                      Capture.JPG

                      but the problem is that a Java run-time less than version 8 will report "Unsupported major.minor version 52.0" when trying to run a class file compiled with Java 8.  Somehow SQLcl (the sql script file, not sqlcl as you mistakenly note in your second post) is not setting JAVA_HOME correctly on the REL6 box.

                       

                      Try reviewing the sql script in the sqlcl/bin directory (especially the checkJavaLocation function), and run it via

                      bash -x sql

                      to list verbose output and see what is actually happening.

                       

                      Cheers

                      • 8. Re: SQLCL Java Error
                        dba_chad

                        Good call on bash -x.  It looks like even with JAVA_HOME explicitly set in my environment AND a local jre under my sqlcl directory, sqlcl sets JAVA_HOME to be a location under my RDBMS binary location.  This actually happens with REL6 or 7, however the reason it works on REL7 is because on this server we have 12.2 which comes with JAVA8.

                        Note:  I renamed the sql executable to sqlcl for clarification sakes when executing.

                         

                        -bash-4.2$ bash -x sqlcl

                        + checkADE

                        + '[' m/opt/app/oracle/product/12.2.0 '!=' m ']'

                        + '[' -d /opt/app/oracle/product/12.2.0/jdk/jre ']'

                        + JAVA_HOME=/opt/app/oracle/product/12.2.0/jdk/jre

                         

                         

                        -bash-4.1$ bash -x sqlcl

                        + checkADE

                        + '[' m/opt/app/oracle/product/12.1.0.2 '!=' m ']'

                        + '[' -d /opt/app/oracle/product/12.1.0.2/jdk/jre ']'

                        + JAVA_HOME=/opt/app/oracle/product/12.1.0.2/jdk/jre

                         

                         

                        I wonder if this a bug with the newest version or if there's a way to override this somehow.

                        • 9. Re: SQLCL Java Error
                          dba_chad

                          Looks like this may be related to this:

                           

                          sqlcl 18.1.1 connect / as sysdba with 11.2.0.4 DB

                          • 10. Re: SQLCL Java Error
                            Glen Conway

                            Very good, so either:

                            1. unset ORACLE_HOME if you are OK without the capability to make bequeath connections or OCI/Thick connections.

                            2. Install an Oracle Instant client and set ORACLE_HOME to the Instant client location.

                             

                            Good luck!