How do I use JDKs 1.2 or 2.0 with 3.3 and avoid a Java Class Cast Exception?

From Support
Jump to: navigation, search

Question:

Using VBJ 3.3 with JDK 1.2 or JDK 2.0 results in error "java.lang.ClassCastException: com.sun.CORBA.iiop.ORB"

The ORB provided with Java is interferring with the operation of VisiBroker components.

The Sun ORB needs to be disabled for VisiBroker applications to work. This is accomplished by passing the "-Xbootclasspath" option to the JVM with an alternate CLASSPATH that contains the location of all the class file components the application will need to operate.

Note: The "-Xbootclasspath" disables the the automatic inclusion of the "java.*" packages also, so they need to be added to the end of the alternate CLASSPATH.

Answer:

Workaround for Sun/Solaris (Portable Bourne Shell Script modifications)

The size of the command line editor buffer may be exceeded by a command which includes the full CLASSPATH, and it is difficult to type in the full CLASSPATH for every command invocation so it is recommended to use script files to run your VisiBroker commands. The best place to add this modification is to the Unix vbj script file, as described below.

Ensure that JAVA_HOME is defined and pointing to your JDK 1.2 or 2.0 installation and that ${JAVA_HOME}/bin is the only JDK version in your PATH. Make sure that the VisiBroker bin directory is also on the PATH. Then add the following lines to the VisiBroker vbj script:
  if ( test -n ${JAVA_HOME} &&
    test -n "`java -version | egrep "(JDK_1.2)|(JDK_2.)"`" );
    then
      javavm="${javavm} -Xbootclasspath:${CLASSPATH}:${JAVA_HOME}/jre/lib/rt.jar:.";
    fi

These lines should be put before the comment:

  1. Once classpath is set, we can print version

The exact line number may change with each patch or release, but look for the comment near line 243.

The environment CLASSPATH should not include any of the JDK .jar files or .class file directories nor should it include any of the VisiBroker .jar files or .class file directories, except for the jar files needed for the optional VisiBroker Services packages (Events, Naming, SSL, etc.).

Replace the line in the VisiBroker vbjc script that reads:
  exec javac $*

with the following lines:
  if ( test -n ${JAVA_HOME} &&
    test -n "`java -version | egrep "(JDK_1.2)|(JDK_2.)"`" );
    then
      javac="javac -bootclasspath ${CLASSPATH}:${JAVA_HOME}/jre/lib/rt.jar:."
    fi
  exec ${javac} $*

Finally to ensure that JAVA_HOME is defined when you load the VisiBroker environment, add the following lines to the end of the vbroker.sh script (or similar functionality to vbroker.csh for C-Shell users):
if ( test -n ${JAVA_HOME} )
  then
    javadir=`which java`
    javadir=`dirname ${javadir}`
    if ( test -n ${javadir} )
      then
         echo "Warning! JAVA not found!"
      else
        JAVA_HOME=${javadir}/..
        export JAVA_HOME
    fi
fi



Article originally contributed by Borland Developer Support