Hi,
I am having a problem with loading classes in an external JAR from a
JNI app. I want to use Microsoft's JDBC driver from an Objective-C++
program, but I can't seem to get the classes to load. I've tried
everything I can think of to get this to work, but I have had a very
hard time trying to find accurate information on embedding Java in
native applications. Sun's JNI tutorial seems to have some outdated
information. I am sure it is just some boneheaded mistake I am
making, but I have tried searching this list and everything else I
could find for what I might be missing and I haven't found it yet.
I've tried the exact same code in a Java app (well, except it was
written directly in Java) and I can access the database, execute
queries, and display results. I've looked at the verbose output for
both and they seem identical, except that the Java version loads the
com.microsoft classes and the Obj-C++ version throws an exception
that it can't find them. Any help would be appreciated it.
The exact error is:
Exception in thread "main" java.lang.ClassNotFoundException: com/
microsoft/jdbc/sqlserver/SQLServerDriver
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:141)
The line of code that causes it is:
env->CallStaticObjectMethod(ClassCls, forNameMID, env->NewStringUTF
("com.microsoft.jdbc.sqlserver.SQLServerDriver"));
I've included the simplest version of the code I can get to reproduce
the error at the end of this e-mail. Copy it to a file named
"jnitest.mm" and then it can be compiled with the line:
g++ -Wall jnitest.mm -framework Foundation -framework JavaVM -o jnitest
You can get the MS SQL Server 2000 Driver for JDBC SP3 at: http://download.microsoft.com/download/4/1/d/
41d3e9c0-64d1-451e-947b-7a4cba273b2d/mssqlserver.tar
Move the tar to its own directory and then open it and the resulting
msjdbc.tar file. Just move the JARs (msbase.jar, mssqlserver.jar,
msutil.jar) from the lib/ dir into /Library/Java/Extensions and that
should be enough to load the class.
It appears that the Java program automatically looks in /Library/Java/
Extensions for additional classes (I don't explicitly mention the
directory when running it). Should my JNI instantiation of the JVM
also look there automatically (i.e., is my explicit setting of
java.class.path necessary)? Also, if anyone else can recommend some
good resources on accessing Java classes from native programs, I
would really appreciate it. I have had a real hard time tracking
anything down.
[pool release];
return 0;
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden