Subject Re: [Firebird-Java] Why: java.lang.ClassNotFoundException: org/firebirdsql/jdbc/FBDriver
Author Mark Rotteveel
On Fri, 01 Mar 2013 00:24:52 -0000, "garyscotthenry"
<gary.henry@...> wrote:
> Here is my system info:
>
> - Server version/model: Installed Firebird-2.5.2.26539_0_Win32.exe
> - OS version: 64-bit Windows 7
> - Client language: Microsoft Visual C++ 2010
> - Client data access interface: JDBC Driver
>
> I have a test program that calls the following functions:
>
> cls = (*env)->FindClass(env, "java/lang/Class");
> mid = (*env)->GetStaticMethodID(env, cls, "forName",
> "(Ljava/lang/String;)Ljava/lang/Class;");
> jstr = (*env)->NewStringUTF(env, "org.firebirdsql.jdbc.FBDriver");
> obj = (*env)->CallStaticObjectMethodV(env, cls, mid, jstr);
>
> The exception returned is:
>
> java.lang.ClassNotFoundException: org/firebirdsql/jdbc/FBDriver
>
> My CLASSPATH is set to the location where I installed
> jaybird-full-2.2.1.jar:
>
> CLASSPATH=
>
D:\tmp\Pivotal\1086514JavaClassNotFound\Firebird\Jaybird\jaybird-full-2.2.1.jar;
> D:\tmp\Pivotal\1086514JavaClassNotFound\Firebird\Jaybird
>
> As far as I know FBDriver should be in jaybird-full-2.2.1.jar. If
anyone
> knows of something I can try to get rid of the ClassNotFoundException
let
> me know.

I don't have much experience with JNI, and none with loading the JVM from
JNI, but as far as I know, when loading a JVM with JNI it ignores the
environment variable CLASSPATH. When using Java it is better to ignore the
existence of CLASSPATH altogether, because most use cases of Java actually
ignore it (I believe one of the designers of Java even said the existence
of that environment variable was a mistake). So not using CLASSPATH will
simplify your life because you know you will need to find a way to set the
classpath specific to your application.

To explicitly set the classpath, the following should work (based on
http://192.9.162.55/docs/books/jni/html/invoke.html ):

jint res;
JavaVM *jvm;
JavaVMInitArgs vm_args;
JavaVMOption options[1];
options[0].optionString =

"-Djava.class.path=D:\tmp\Pivotal\1086514JavaClassNotFound\Firebird\Jaybird\jaybird-full-2.2.1.jar";
vm_args.version = 0x00010002;
vm_args.options = options;
vm_args.nOptions = 1;
vm_args.ignoreUnrecognized = JNI_TRUE;
/* Create the Java VM */
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);

Also if you use Java 6 or higher, you do not actually need to load the
org.firebirdsql.jdbc.FBDriver class yourself as the DriverManager will take
care of it for you. But if you do want to load it yourself, you don't need
to use Class.forName(..), using:
cls = (*env)->FindClass(env, "org/firebirdsql/jdbc/FBDriver");
should suffice AFAIK.

Mark