Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Usage of JACOB in java.

    While i am running the code given below it shows the error as com.jacob.com package doesn't exist.at present am using jdk 1.6.0 version.have i need to install any software?


    import com.jacob.activeX.ActiveXComponent;
    import com.jacob.com.Dispatch;
    import com.jacob.com.EnumVariant;
    import com.jacob.com.Variant;
    public class NetworkInterfaceQuery {
    /**
    * List the network interfaces and thier statistics.
    *
    * @param args
    */
    public static void main(String[] args) {
    String host = "localhost"; //Technically you should be able to connect to other hosts, but it takes setup
    String connectStr = String.format("winmgmts:\\\\%s\\root\\CIMV2", host);
    String query = "SELECT * FROM Win32_PerfRawData_Tcpip_NetworkInterface"; //Started = 1 means the service is running.
    ActiveXComponent axWMI = new ActiveXComponent(connectStr);
    //Execute the query
    Variant vCollection = axWMI.invoke("ExecQuery", new Variant(query));
    //Our result is a collection, so we need to work though the.
    EnumVariant enumVariant = new EnumVariant(vCollection.toDispatch());
    Dispatch item = null;
    while (enumVariant.hasMoreElements()) {

    item = enumVariant.nextElement().toDispatch();
    //Dispatch.call returns a Variant which we can convert to a java form.
    String BytesReceivedPerSec = Dispatch.call(item,"BytesReceivedPerSec").toString ();
    String BytesSentPerSec = Dispatch.call(item,"BytesSentPerSec").toString();
    String BytesTotalPerSec = Dispatch.call(item,"BytesTotalPerSec").toString();
    String Caption = Dispatch.call(item,"Caption").toString();
    String CurrentBandwidth = Dispatch.call(item,"CurrentBandwidth").toString();
    String Description = Dispatch.call(item,"Description").toString();
    String Frequency_Object = Dispatch.call(item,"Frequency_Object").toString();
    String Frequency_PerfTime = Dispatch.call(item,"Frequency_PerfTime").toString( );
    String Frequency_Sys100NS = Dispatch.call(item,"Frequency_Sys100NS").toString( );
    String Name = Dispatch.call(item,"Name").toString();
    String OutputQueueLength = Dispatch.call(item,"OutputQueueLength").toString() ;
    String PacketsOutboundDiscarded = Dispatch.call(item,"PacketsOutboundDiscarded").toS tring();
    String PacketsOutboundErrors = Dispatch.call(item,"PacketsOutboundErrors").toStri ng();
    String PacketsPerSec = Dispatch.call(item,"PacketsPerSec").toString();
    String PacketsReceivedDiscarded = Dispatch.call(item,"PacketsReceivedDiscarded").toS tring();
    String PacketsReceivedErrors = Dispatch.call(item,"PacketsReceivedErrors").toStri ng();
    String PacketsReceivedNonUnicastPerSec = Dispatch.call(item,"PacketsReceivedNonUnicastPerSe c").toString();
    String PacketsReceivedPerSec = Dispatch.call(item,"PacketsReceivedPerSec").toStri ng();
    String PacketsReceivedUnicastPerSec = Dispatch.call(item,"PacketsReceivedUnicastPerSec") .toString();
    String PacketsReceivedUnknown = Dispatch.call(item,"PacketsReceivedUnknown").toStr ing();
    String PacketsSentNonUnicastPerSec = Dispatch.call(item,"PacketsSentNonUnicastPerSec"). toString();
    String PacketsSentPerSec = Dispatch.call(item,"PacketsSentPerSec").toString() ;
    String PacketsSentUnicastPerSec = Dispatch.call(item,"PacketsSentUnicastPerSec").toS tring();
    String Timestamp_Object = Dispatch.call(item,"Timestamp_Object").toString();
    String Timestamp_PerfTime = Dispatch.call(item,"Timestamp_PerfTime").toString( );
    String Timestamp_Sys100NS = Dispatch.call(item,"Timestamp_Sys100NS").toString( );
    System.out.println("Name = " + Name);
    System.out.println("BytesReceivedPerSec = " + BytesReceivedPerSec);
    System.out.println("BytesSentPerSec = " + BytesSentPerSec);
    System.out.println("BytesTotalPerSec = " + BytesTotalPerSec);
    System.out.println("Caption = " + Caption);
    System.out.println("CurrentBandwidth = " + CurrentBandwidth);
    System.out.println("Description = " + Description);
    System.out.println("Frequency_Object = " + Frequency_Object);
    System.out.println("Frequency_PerfTime = " + Frequency_PerfTime);
    System.out.println("Frequency_Sys100NS = " + Frequency_Sys100NS);
    System.out.println("OutputQueueLength = " + OutputQueueLength);
    System.out.println("PacketsOutboundDiscarded = " + PacketsOutboundDiscarded);
    System.out.println("PacketsOutboundErrors = " + PacketsOutboundErrors);
    System.out.println("PacketsPerSec = " + PacketsPerSec);
    System.out.println("PacketsReceivedDiscarded = " + PacketsReceivedDiscarded);
    System.out.println("PacketsReceivedErrors = " + PacketsReceivedErrors);
    System.out.println("PacketsReceivedNonUnicastPerSe c = " + PacketsReceivedNonUnicastPerSec);
    System.out.println("PacketsReceivedPerSec = " + PacketsReceivedPerSec);
    System.out.println("PacketsReceivedUnicastPerSec = " + PacketsReceivedUnicastPerSec);
    System.out.println("PacketsReceivedUnknown = " + PacketsReceivedUnknown);
    System.out.println("PacketsSentNonUnicastPerSec = " + PacketsSentNonUnicastPerSec);
    System.out.println("PacketsSentPerSec = " + PacketsSentPerSec);
    System.out.println("PacketsSentUnicastPerSec = " + PacketsSentUnicastPerSec);
    System.out.println("Timestamp_Object = " + Timestamp_Object);
    System.out.println("Timestamp_PerfTime = " + Timestamp_PerfTime);
    System.out.println("Timestamp_Sys100NS = " + Timestamp_Sys100NS);
    System.out.println("-------------------------------------------");


    }
    }
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,243
    Rep Power
    19

    Default Re: Usage of JACOB in java.

    The classes used have to be available on the compile-time and run-time classpath.

    Did you even download JACOB?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Usage of JACOB in java.

    can you explain in detail ?

  4. #4
    Join Date
    Jan 2012
    Posts
    10
    Rep Power
    0

    Default Re: Usage of JACOB in java.

    now i have downloaded JACOB.but still finding a problem in compiling the code.is there any additional thing we have to do while setting the class path?

Similar Threads

  1. Java web usage
    By mDennis10 in forum New To Java
    Replies: 0
    Last Post: 12-14-2011, 09:13 AM
  2. How to determine CPU usage using Java?????
    By JavaEmpires in forum New To Java
    Replies: 5
    Last Post: 03-16-2011, 04:49 AM
  3. JACOB error, putObject failed
    By MaJellin in forum New To Java
    Replies: 0
    Last Post: 03-05-2010, 08:17 AM
  4. run java program in 100% usage
    By mr_empty in forum Advanced Java
    Replies: 5
    Last Post: 01-22-2010, 10:35 PM
  5. How to use Jacob component in a Java Applet?
    By ollyworks in forum Java Applets
    Replies: 1
    Last Post: 09-09-2009, 04:07 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •