I am trying to access my java class from VB (without going the c/jni route). It always stops at CreateObject(java:myClass). I am using the Sun jdk1.3 on Windows2000 with VB6. I tried javareg \register \class:myClass codebase: "c:\mypath" as well as several variations. How can I get VB to be able to create a java object? Any help would be greatly appreciated. ------------------
Rob Whelan
Ranch Hand
Joined: Oct 18, 2000
Posts: 33
posted
0
I was on a project last year in which I needed to handle some fairly extensive communication between a VB application (providing IVR and faxing capabilities) and a Java application (applet GUI, DB access, and main logic). After some evaluation of the communication challenges, I ended up just having the two apps communicate over a socket, sending/receiving messages in XML. If you need to start the Java app, isn't there a way to access the command line from VB (my VB experience is _very_ limited)? I think MS also provides some kind of ActiveX-Java bridge, probably built into Visual J++... I don't know. I mostly try to keep away from that stuff
debbie collins
Greenhorn
Joined: Oct 11, 2000
Posts: 9
posted
0
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.
Tristan Havelick
Greenhorn
Joined: Jul 29, 2000
Posts: 7
posted
0
Used this to try to access a java object from an ASP page.. It does not work properly, wondering if anyone has any ideas. When I run the class with Sun's VM from the command line (I wrote a main() function to test it.) and it works. But when I run the ASP page that accesses the class I get the following error: Error Type: Java Exception (0x80004005) java.lang.NoSuchMethodError: java/awt/image/ColorModel: method loadLibraries()V not found /dev/resizer/resize.asp, line 17 It alsomt seems that the M$ VM is not fully Java 2 compliant. For instance when I run the class from the command line with the M$ JVeiw program I get the following: E:\Program Files\Microsoft SDK for Java 4.0\Bin>jview D:\dev\ImageResizer java.lang.NoSuchMethodError: java/awt/image/ColorModel: method loadLibraries()V not found at java/awt/image/BufferedImage.<clinit> at ImageResizer.imageToBuffered at ImageResizer.loadBufferedImageIcon at ImageResizer.createResizedFile at ImageResizer.main If anyone has any ideas, I've posted the source code for the class and the ASP page at: http://home.havelick.com/share
debbie collins
Greenhorn
Joined: Oct 11, 2000
Posts: 9
posted
0
Tristan, I no longer use that method, but rather the getObject(java:com.etc.ClassName) available in VB. This requires only that your class file, com/etc/ClassName.class, or a jar containing it be in your classpath and that there is a no argument constructor for the class. Microsoft's vm will be invoked and it is not up to JDK1.2, so care must be taken. Usually running with jview first is a good indication. Good luck, Debbie
Tristan Havelick
Greenhorn
Joined: Jul 29, 2000
Posts: 7
posted
0
I was afraid that the M$ VM wasn't fully Java2 compliant. I guess I'll just bite the bullet and write a servlet to do that part of my site. Probably should have done that from the begining, but oh well.
mohamed zafer
Ranch Hand
Joined: Nov 03, 2000
Posts: 62
posted
0
Hello There, I have written a java application that is invoked by a VB component. The java program is invoked successfully by the VB component, but it throws a runtime exception. The message of the exception is ------------------------------------------------------ Can't canonicalize input: UTF-8 [Could not load class: sun.io.CharToByteUTF-8] ------------------------------------------------------ I get the same exception if i run the application in the DOS-prompt using th MS VM (i.e., using "jview"), But it works fine if I use the sun's VM (i.e., java). Also from the rt.jar I found that there is no class called "sun.io.CharToByteUTF-8" but there is a class called "sun.io.CharToByteUTF8". Any idea what could be the problem. Also can I force the MS to use the Sun Runtime when I invoke the java application from VB rather than using the MS VM. Thanks in advance.. Zafer
debbie collins
Greenhorn
Joined: Oct 11, 2000
Posts: 9
posted
0
<pre> 1. Microsoft jvm (java virtual machine) must be installed on your machine. This is free and can be downloaded 2. A reference to XXX.jar must be included in your classpath. Example: ..;C:\WINNT\java\classes\classes.zip;C:\WINNT\java\classes;.;%systemroot%\java\classes;c:\jdk1.3\lib\tools.jar;c:\jdk1.3\jre\lib\rt.jar;c:\jdk1.3\jre\lib\il8n.jar;c:\jdk1.3\jre\lib \ext\jms.jar; c:\Program Files\NewScoringManager\Ace.jar 3. The PATH environment variable must include the "bin" directories for the jdk and the ms sdk. 4. After initial setup, run clspack -auto from c:\ in a DOS window. Here is an example: 'Get the java log manager Dim objJavaLogMgr As Object Set objJavaLogMgr = GetObject("java:com.sierracities.util.VBSingletonAccess") Dim objJavaLog As Object Set objJavaLog = objJavaLogMgr.getSingleton( _ "com.sierracities.util.Log")
Good luck. Remember - it uses the Microsoft jvm and is behind JDK1.2 </pre>
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.