Help Icon
Search Results for

    Show / Hide Table of Contents

    Add Reference in Java

    Jacob is a Java COM bridge that can be downloaded and used to access the COM Automation components from Java.
    To use Jacob in Eclipse perform the following steps after downloading it as an archive and then extracting it:

    1. In Eclipse right click on the Java Project and hover over the 'Build Path' option and then select 'Configure Build Path...' Open reference dialogue

    2. In the 'Libraries' tab select the 'Classpath' option and then click on the button 'Add External JARs...'. There the 'jacob.jar' can be searched on your file system and added to the classpath. Open reference dialogue

    3. Afterwards expand the 'jacob.jar' by clicking the arrow to left of the jar. Then select 'Native library location'. Open reference dialogue

    4. Set the 'Native Library Location' to the directory that contains the jacob.dll files for 64 and 32 bit (which are downloaded alongside the 'jacob.jar'). Open reference dialogue

    After performing these steps the COM Automation components can be accessed by using 'invoke' as well as 'getProperty' to access the methods and properties of the COM Automation components:

    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.*;
    
    public class automationInterfaceComClient {
    
    	public static void main(String[] args) {
    		
    		ActiveXComponent bode = null;
    		
    		try {
    			ActiveXComponent automationInterface = new ActiveXComponent("OmicronLab.VectorNetworkAnalysis.AutomationInterface");		
    			bode = automationInterface.invokeGetComponent("Connect");
    			ActiveXComponent transmission = bode.getPropertyAsComponent("Transmission");		
    			ActiveXComponent s21Measurement = transmission.invokeGetComponent("CreateS21Measurement");
    				
    			Variant[] sweepArgs = new Variant[] {
    					new Variant(1000),
    					new Variant(100000),
    					new Variant(201),
    					new Variant(0)
    			};
    			
    			s21Measurement.invoke("ConfigureSweep", sweepArgs);		
    			s21Measurement.invoke("ExecuteMeasurement");
    			ActiveXComponent results = s21Measurement.getPropertyAsComponent("Results");
    			
    			SafeArray magnitudes = results.invoke("Magnitude", 0).toSafeArray();	
    			SafeArray frequencies = results.getProperty("MeasurementFrequencies").toSafeArray();
    			
    			for (int i = 0; i <= frequencies.getUBound(); i++) {
    				System.out.println(String.format("Value: %s, Frequency %s", magnitudes.getDouble(i), frequencies.getDouble(i)));
    			}
    		}
    		catch(Exception ex) {
    			ex.printStackTrace();
    		}
    		finally {
    			bode.invoke("ShutDown");
    		}
    	}	
    }
    
    Note

    In earlier versions we suggested to use Com4J. This Java COM Bridge does no longer work though. Contrary to Com4J Jacob uses late binding instead of early binding. Due to this, the 'invoke' and 'getProperty' methods have to be used to access the COM Automation component's methods and properties. Using COM is not recommended for new developments. We recommend using the SCPI interface.

    In this article
    Back to top Generated by DocFX