2 Replies Latest reply on Feb 4, 2017 12:24 PM by Roland Schwarz

    Can you use Java to access the API

    Gordon Sandeman

      Have a requirement to access content in Solidworks for use by 3rd party system.  3rd party system provides an integration framework that is Java based but from what I can see the Solidworks API is .NET only.  What's the recommended strategy/experiences for calling Solidworks services from Java?

        • Re: Can you use Java to access the API
          Amen Allah Jlili

          I would really love to see someone post something on how to do this in Java as it is more used to than .NET (industrially - some might disagree).
          Technically speaking, the SW API is COM-based so it should be platform/language independant.
          Take a look at this portability guide: Accessing COM Components from the Java Language

          To access a COM component, run the JActiveX tool on a COM type library (.tlb file) or a COM DLL containing an embedded type library. The JActiveX tool, which ships with Visual J++ 6.0 and the Microsoft SDK for Java, generates wrappers for each coclass and COM interface in the type library. These wrappers, called Java Callable Wrappers (JCWs), are proxies for the actual COM objects and contain @com directives that are understood by the Java-language compiler (jvc.exe). You then import these wrappers into an application and compile the wrappers along with the application code. The @com directives in the wrappers are compiled into attributes in the .class files and are interpreted at run time by the Microsoft Java Virtual Machine (MSJVM).

          To create an instance of a COM object, call new on the appropriate wrapper. The object can then be cast to the interfaces and methods can be called on them. MSJVM uses the @com directives in the generated wrappers to do the following:

          • Locate and call CoCreateInstance on the COM coclass.
          • Translate method calls on the wrapper to calls on the actual COM object.
          • Manage references to the COM object.
          • Marshal parameters between COM and the Java language.

          Java-language developers will use the COM object just as if they were using any other Java-language object, and without dealing with any of the details, as a typical COM developer would.

          You can also host ActiveX controls in the Java language.


          Amen JLILI

          • Re: Can you use Java to access the API
            Roland Schwarz

            It's been done. I've seen some blog posts, but it was a long time ago. As I recall it involves writing a ton of class objects to make all the connections.