PRB: NoClassDefFoundError Accessing a COM Object Through Java

Last reviewed: January 29, 1998
Article ID: Q178560
The information in this article applies to:
  • Microsoft Visual J++, versions 1.0, 1.1
  • Microsoft Win32 Virtual Machine for Java
  • SDK for Java, versions 2.0, 2.01

SYMPTOMS

When executing a Java Application that calls a COM object like an ATL Server, you may sometimes get the following error message on the COM object:

   error: java.lang.NoClassDefFoundError:

The error occurs on the line where you create a new COM object in the Java Class.

CAUSE

One reason why you may get this error could be related to missing parameter attributes for the methods in the COM object's IDL file.

RESOLUTION

Check your methods in the IDL file so that they have the right attributes like [in],[out],[retval] and so on. Once modifying the IDL file, rebuild your COM Server, and rerun JavaTLB or JACTIVEX on the COM Object's Type Library so that the changes gets reflected.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Create a default ATL COM object using VC5.0. Name it AtlServ.

  2. Add a new ATL COM object to the above project. This can be done by right-clicking in Class View and selecting New ATL Object. This will bring up the ATL Object Wizard. Select Simple Object in it and click Next. Now select the Names Tab and name the object as Test.

  3. Add a method to the IDL file as follows:

          ........
          interface ITest : IDispatch
          {
    
             [id(1), helpstring("Hello")] HRESULT TestMethod(BSTR* strGUID);
          };
          ..........
    
    

  4. Add declaration/implementation to this method in the .cpp and .h

        files of your Test ATL COM Object as follows. Declare this method in
        the Test.h file as follows:
    

          .............
          public:
          STDMETHOD(TestMethod)(BSTR* a);
    

    Following is its implementation:

          // Test.cpp : Implementation of CTes
          ..................
          STDMETHODIMP CTest::TestMethod(BSTR* a)
          {
    
             USES_CONVERSION;
             *a = SysAllocString(T2OLE("This is a test!"));
             return S_OK;
          }
    
    

  5. Now build the ATL Server object, which should also register it.

  6. Run JAVATLB or JACTIVEX on the server you created in Step 1. If you are using JACTIVEX, then you will have to use JVC version 4337 or greater that ships with the SDK2.0 and 2.01 for Java in order to build your Java applet.

  7. Create a new Java project using Visual J++ 1.1 and create a new class as follows:

          import atlserv.*;      //This is your ATl Server Object created in
                                 //Step 1.
    
          public class Main
          {
             public static void main(String args[])
            {
                ITest a = (ITest) new Test();
            }
         }
    
    

  8. Build the class and copy it to <windir>/java/lib. where <windir = WINNT or WIN95>.

  9. When running this application using JVIEW you will get the NoClassDefFoundError in the Command-Prompt window.

  10. To fix this problem, specify the [out] attribute to the method in the IDL file as follows:

          interface ITest : IDispatch
          {
    
             [id(1), helpstring("Hello")] HRESULT TestMethod([out]BSTR*
              strGUID);
          };
    
    

  11. Now rebuild your ATL server, and rerun JAVATLB or JACTIVEX on the ATL Server's Type Library so that the changes gets reflected.

  12. You should now be able to run your Java application without any problems.

REFERENCES

For the latest Knowledge Base articles and other support information on Visual J++ and the SDK for Java, see the following page on the Microsoft Technical Support site:

   http://support.microsoft.com/support/visualj/
   http://support.microsoft.com/support/java/


Additional query words: NoClassDefFoundError atl server com

Keywords : JCOM
Technology : kbInetDev internet
Version : WINDOWS:1.0,1.1,2.0,2.01
Platform : WINDOWS
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: January 29, 1998
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.