This was sent by a fellow programmer and it does work. The only problem I'm having now is that the System.loadLibrary in my java stuff can't find the dll. It works fine under Microsoft's jvm or Sun's jvm from the command line, but not when invoked thru VB.
1. your class files must be in a microsoft jvm trusted directory. this is
either WINNT\java\trustlib (or a subdirectory therein) or a directory
specified in the registry key HKLM\SOFTWARE\Microsoft\Java
VM\TrustedClasspath.
2. any other classes that your class needs to access must be in the
microsoft jvm classpath. this is specified in the registry key
HKLM\SOFTWARE\Microsoft\Java VM\Classpath. as an example, i use the
following value for the key (notice the inclusion of the jdk runtimes):
"C:\WINNT\java\classes\classes.zip;%systemroot%\java\classes;..;c:\jdk1.3\li
b\tools.jar;c:\jdk1.3\jre\lib\rt.jar;c:\jdk1.3\jre\lib\i18n.jar;c:\jdk1.3\jr
e\lib\ext\jms.jar".
3. you must have either ms visual j++ or the ms sdk for java installed (so
you can run javareg and clspack).
4. you must have the "bin" directories for the jdk and the ms sdk (or
visual j++) in your PATH environment variable. as an example, i use the
following PATH:
"%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\MSSQL7\BIN
N;C:\jdk1.3\bin;C:\Program Files\Microsoft SDK for Java 4.0\Bin".
5. you must run the following command-line "clspack - auto"; this creates a
package containing some standard classes that the microsoft jvm uses and
puts it in "WINNT\java\classes\classes.zip" (notice it in the Classpath
registry key above).
6. your object cannot rely on java constructors, since they are not
callable from VB. instead, write a function that you call explicitly to do
any initializtion you may need.
Once all of these crieria are met, the following steps are necessary to
register and the java class as a COM object.
1. run javareg. be sure to include the option to create the typelibrary -
if you run the command with /typelib set and it is successfull, you know
that all of your classes/referenced classes are in the proper directories.
if it does not run properly, you know you that you are missing a file
somewhere. this is the ONLY way that i have found to make sure your class
will behave properly as a COM object. as an example, here is a javareg
command line; it assumes that you are at a command prompt in the
WINNT\java\trustlib directory and that your class, named "ImplFoo" is in the
subdirectory com\debbie\foo (WINNT\java\trustlib\com\debbie\foo): "javareg
/register /class:com.debbie.foo.ImplFoo /progid:com.debbie.foo.ImplFoo
/codebase:.\com\debbie\foo\ImplFoo.class
/typelib:.\com\debbie\foo\ImplFoo.tlb".
2. once javareg is successful, use the following line to create the object
in VB (do not include the "java:" prefix):
Dim myJava AS Object
Set myJava = CreateObject("com.debbie.foo.ImplFoo")
NOTES:
- the name specified in CreateObject is whatever you set as the /progid
parameter of javareg - this must match the name you specify in /typelib
(except for the extension)
-if the javareg command fails when you have the /typelib parameter
specified, make sure to do a "javareg /unregister" on the object to clean
out the registry before reattempting to register the object. i have seen
many stray references created in the registry in the past.