Java Access COM components

Source: Internet
Author: User
Tags command line net version thread access
Access
Author: Junsan Jin



Date: 2005-4-14



Version: 1.0



Mailbox: junsan21@126.com; Junnef21@sohu.com



Blog:http://blog.csdn.net/junnef



Disclaimer: I reserve all the rights of this article. Please keep this information if you need to refer to it.







First, preparatory work



To understand the concept first, JACOB is the acronym for Java-com Bridge, providing automated access to COM, and also accessing the COM components or Win32 system libraries under the Windows platform through JNI functionality. This is the result of an open source project that started in 1999, and many users have made changes to the project to make their own contribution.



Best place to support: Http://groups.yahoo.com/group/jacob-project



Jacob Download Address:



http://sourceforge.net/project/showfiles.php?group_id=109543&package_id=118368



Here is the latest release version of Jacob1.9.



Ii. installation of Jacob



Jacob's installation was very simple, we unpacked the downloaded Jacob_1.9.zip and found the Jacob.dll and Jacob.jar two files in the folder. Jacob goes directly to the system's System32 folder, even if it's not registered (or copied to the JDK or JRE's Bin directory, and the current test file is in the same directory as long as it's in Java.library.path). The Jacob.jar is set to Classpath, or the same is the case for setting up an extension library in the engineering of the IDE development environment.



Do the above work, you can use the normal.



Third, the example demonstration



Create the following test file:







////////////////////////////////////////////////



Apptest.java



///////////////////////////////////////////////



Import com.jacob.com.*;



Import com.jacob.activex.*;







public class Apptest



{



public static void Main (string[] args)



{



Create COM component in event thread



Activexcomponent SC = new Activexcomponent ("ScriptControl");



Dispatch SControl = Sc.getobject ();



Dispatch.put (SControl, "Language", "VBScript");







Use COM component in same thread



Variant v = dispatch.call (SControl, "Eval", Args[0]);



System.out.println (V.tostring ());



}



}







Open the command line mode, to the directory where the Java file is located, and type the command:







Javac Apptest.java



Java apptest 1+2*3







The output will be:



7






The introduction of the simple, more things to our unpacked folder under the DOC package to see the document, here is not much to say, the most important thing is to clarify the role of the class library and the use of the method on the line. I'll have time later

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.