INFO: Frequently Asked Questions for Java/COM/DCOM

Exención de responsabilidades de contenido KB retirado

Este artículo se refiere a productos para los que Microsoft ya no ofrece soporte técnico. Por tanto, el presente artículo se ofrece "tal cual" y no será actualizado.

Summary

This article covers some of the Frequently Asked Questions (FAQ) about Java/COM/DCOM.


For other Java related FAQs search the Web at
http://www.msdn.microsoft.com/support/ for 'JAVA' and 'FAQ'.

More Information

Q. 1. I am trying to use an ActiveX automation object written in Java (the COMCallingJava sample) from Visual Basic but I keep getting "Out of Memory" errors.


A. This is normally caused by the Operating System not being able to find the Java class file that implements the ActiveX automation server. The class file that implements the Server must be copied to the java classpath (for instance: \windows\java\lib) for OLE object creation to work properly for Java class files. A common example of this is the COMCallingJava sample application supplied with Visual J++. It will work fine when the sample is first built because the CEuclid.class is in the local directory (which the Developer Studio adds to the CLASSPATH before running Internet Explorer). Trying to run the VBDriver Visual Basic sample code supplied in the VBDriver project subdirectory will then fail with the "Out of Memory" error. This can be remedied by copying CEuclid.class to the \windows\java\lib directory. You can also set the output directory in the project build options so that the class file is automatically built in the appropriate classpath directory. This information is also documented in the following Knowledge Base article:

163720 : PRB: Getting Out Of Memory Error with COMCallingJava.
Q. 2. Why does Java misinterpret a Boolean value that is returned by a COM object?


A. This is a bug, which has been fixed with the latest Microsoft virtual machine (Microsoft VM). Please follow the link to http://www.msdn.microsoft.comto download the latest Microsoft VM. This version of the Microsoft VM requires Internet Explorer 3.01. This information is also documented in the Microsoft Knowledgebase article:

162966 FIX: COM Object Returns Incorrect Value for Bool
Q. 3. Why do I get a "java.lang.ClassFormatError", when I call Automation methods from VJ++ that takes parameters of Pointer type BSTR*, long*?


A. For information on this refer to the Microsoft Knowledge Base article:

165550 BUG: JavaTLB Generates Invalid Classes for MFC Server
Q. 4. Why do I get an "exception:java.lang.ClassCastException:xl5en32/_ExcelApplication" error, when creating a new _ExcelApplication class and type-casting it to the Application interface?


A. For information on this refer to the Microsoft Knowledge Base article:

169806 PRB: ClassCastException Error When Using Excel Object in Java
Q. 5. Do Visual J++ applets or applications support ActiveX control containment?


A. Currently, the Microsoft virtual machine build 1518 does not support the containment of ActiveX controls. You cannot place an ActiveX control that has a user interface or that sources or sinks events directly onto an applet without implementing all of the ActiveX control containment and inventing interfaces yourself. To be clear, you can use ActiveX automation servers from Java, and you can write ActiveX automation servers in Java utilizing the Microsoft VM's ability to expose Java classes as ActiveX objects. You can also have ActiveX controls and Java applets on the same Web page and have them interact (see the OLEControls sample in Visual J++).


However the SDK for Java 2.0x provides ActiveX Control Containment support through Beans. It exposes any Bean as an ActiveX Control and any ActiveX Control as a Bean. The SDK for Java also includes samples that illustrates how to do this. You can download this SDK from
http://www.msdn.microsoft.com

Q. 6. How do I use the COMCallingJava sample as a DCOM Server?


A. First you should build the sample and run it as a conventional (InProcess) automation server. Do this by following the instructions outlined in the readme.html that is installed with the sample. More information on how to use this sample via DCOM, can be found in the Knowledgebase article:

162164 : BUG: Using Java Servers and DCOM
Q. 7. When I try to use JavaReg with the /surrogate switch in order to use my Automation Server written in Java as a DCOM server, the Java console pops up and closes when run on a remote machine and my client application hangs?


A. You may experience various problems when you try to use an Automation Server written in Java as a DCOM server. These problems can include hanging, timeouts, out of memory errors, interface not found errors, and other errors. These errors are generally caused by not registering the Java COM object properly on both the client and DCOM server machines. The JAVAREG (version 1.0) that shipped with Microsoft Visual J++, versions 1.0 and 1.1 implemented a surrogate process itself, but it had some bugs making it difficult to setup Java DCOM servers and clients. This bug is documented in the following article in the Microsoft Knowledge Base:

162164 : BUG: Using Java Servers and DCOM
The DCOM support now in Windows 95 and Windows NT 4.0 with SP2 and SP3 supports a surrogate as part of the system, so the surrogate support with JAVAREG 1.0 has been dropped.


JAVAREG 2.0 is a new tool that ships with the Microsoft SDK for Java 2.0x and this tool has fixed the bugs associated with JAVAREG 1.0 and supports remote access to a Java COM object using the system provided surrogate process. This information is also documented in the following article in the Microsoft Knowledge Base:

173790 : HOWTO: Using DllSurrogate Support for Java/DCOM Servers
You can download this SDK from http://www.msdn.microsoft.com

Q. 8. Why do I get "Failed to Create Object" error message, when trying to instantiate a COM object written in Java?


A. The following is a checklist that provides some of the common causes for this error. Make sure:

  1. The Java class is in the classpath.
  2. Your Java method is declared 'public'.
  3. You need to register the class file (using javareg.exe).
  4. Install the latest Microsoft VM from
    http://www.msdn.microsoft.com if you are attempting to use CreateObject().
  5. Follow the steps in the Visual J++ sample named COMCALLINGJAVA.
Q. 9. Why don't I need to use IDL anymore when creating a Java com object that is used through IDispatch?


A. For information on this refer to the Microsoft Knowledge Base article:

172202 INFO: Implementing Java Automation Objects using AutoIDispatch
Q. 10. Is there a way to disable this Auto IDispatch mechanism of the Microsoft virtual machine?


A. You can implement the system interface com.ms.com.NoAutoScripting to disable the Auto IDispatch for all instances of a class.


Q. 11. I get ComFailException:<80020005h>Type Mismatch error, when trying to use the Navigate method of the IWebBrowserApp interface? How do I invoke Internet Explorer from Java and navigate to a URL?


A. The following code snippet illustrates creating a Java Object based on the Microsoft Internet Explorer and calling the Navigate method:
  1. Create a default Java Applet or an Application.
  2. Run JavaTLB on Microsoft Internet Controls.
   import com.ms.com.*;
import shdocvw.*;
public class Navigate
{
IWebBrowserApp testBrowser = null;

public static void main( String args[] )
{
IWebBrowserApp testBrowser = (IWebBrowserApp)new InternetExplorer();
testBrowser.getApplication();
testBrowser.putVisible(true);
Dispatch.call(testBrowser, "Navigate", "http://www.msdn.microsoft.com");
}
}
The Dispatch.call method is documented in the Microsoft SDK for Java Documentation, which can be found at the following Web site:

Q. 12. I am able to automate Excel 7.0 from Java, but I am finding the classes and interfaces to be quite different in Excel 8. How do I automate Excel 8.0 from Java?


A. For information on this refer to the Microsoft Knowledge Base article:

169796 HOWTO: Automate Excel from Java
Q. 13. When I use JavaTLB to generate classes from some COM object libraries, I get an error J5008. Should I be concerned?


A. Often, the cause of this warning is that the method uses a type that is not supported in Java. All methods that produce a J5008 warning are omitted from the class file. Note that JavaTLB has been replaced by JActiveX in the SDK for Java 2.0x.


For additional information, please see the following article in the Microsoft Knowledge Base:

167952 PRB: JavaTLB Emits J5008 Warnings for Some COM Objects
Q.14. I get a 'java.lang.NoClassDefFoundError: com/ms/com/LicenseMgr' error when I run an applet generated by the Database Wizard for Java?


A. When an applet is run in Internet Explorer and outside of Developer Studio, the applet is not trusted and does not have access to ILicenseMgr. This problem is by design since only trusted applets should have access to the ILicenseMgr. The ILicenseMgr allows the creation of COM objects on the client.


To fix the problem, create a CAB file that contains the classes of the applet and digitally sign the CAB with the CodeSign kit. For more information on Cab and Sign technology, look in the "Cab&Sign" directory on the Visual J++ CD-ROM. For the latest info on CAB technology please refer to http://www.msdn.microsoft.com

For additional information, please see the following article in the Microsoft Knowledge Base:

169810 PRB: java.lang.NoClassDefFoundError:com/ms/com/LicenseMgr Error
Q. 15. Why does Visual Basic crash when calling a Java Object that has a method that returns a Boolean value?


A. This problem has been fixed in JActiveX, where it maps VT_BOOL to a 2- byte value. You can get JActiveX, by installing the SDK for Java 2.0X from
http://www.msdn.microsoft.com Note that JavaTLB has been replaced by JActiveX in the SDK for Java 2.0X.


Q. 16. When I run a Java Application that calls a COM object like an ATL Server, I get a "NoClassDeffoundError" on the COM object. The error occurs on the line where I create a new COM object in the Java Class?


A. One reason why you may get this error could be related to missing parameter attributes for the methods in the ATL servers IDL file. For example if you have a method like the following example:


[id(1), helpstring("method GetString")] HRESULT GetString(BSTR* mystr);
JavaTLB executes fine on this TLB. However when you execute your Java Application that calls this COM object, that is ISomeInterface m_intf = (ISomeInterface) new CAtlObj, it fails at this line with a "java.lang.NoClassDeffoundError". To fix the problem, change the IDL method to include the [out] attribute. For example the method looks like this:

[id(1), helpstring("method GetString")] HRESULT GetString([out]BSTR*
strGUID);
So check your methods in the IDL file so that they have the right attributes like [in], [out], [retval], and so on. Once you've modified the IDL file, rebuild your ATL server, and rerun JavaTLB on the ATL Servers Type Library so that the changes gets reflected.


For additional information, please see the following article in the Microsoft Knowledge Base:


178560 PRB: NoClassDefFoundError Accessing a COM Object Through Java

References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

(c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Rafael M. Munoz, Microsoft Corporation.

Propiedades

Id. de artículo: 168935 - Última revisión: 01/21/2013 - Revisión: 1

Comentarios