COM4j无法连接到HP Quality Center

时间:2012-06-25 09:41:16

标签: java hp-quality-center com4j

我正在尝试使用com4j生成HP Quality Center OTACLien.dll的界面。

我使用以下命令并获得此错误。

com4j版本20110322

OTAClient.dll版本9.1

E:\dum>java -jar tlbimp.jar -o "e:\OutPutofDLL" -p ota "e:\dum\qcdll\OTAClient.dll"
Generating definitions from TDAPIOLELib
Unable to handle the type Date*
  method GetFollowUp
  interface IFollowUpManager
Unable to handle the type (IDISPATCH)*
  method get_ItemFromServer
  interface IComponentFactory

生成了一些类,但是当我尝试使用以下代码连接到QC时,我得到错误。

import com4j.ComException;

import ota.ClassFactory;
import ota.ITDConnection;

public class OCComtest {

    public static void main(String[] args) {
        try{

        ITDConnection connection = ClassFactory.createTDConnection();
        connection.initConnectionEx("http://qc_server_IP:8080/qcbin/");
        System.out.println(connection.connected());
        }catch (ComException e) {
            e.printStackTrace();
        }
        }
}

错误记录

Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
    at com4j.ComThread.execute(ComThread.java:203)
    at com4j.Task.execute(Task.java:25)
    at com4j.COM4J.createInstance(COM4J.java:97)
    at com4j.COM4J.createInstance(COM4J.java:72)
    at ota.ClassFactory.createTDConnection(ClassFactory.java:16)
    at tests.OCComtest.main(OCComtest.java:13)
Caused by: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
    at com4j.Native.createInstance(Native Method)
    at com4j.COM4J$CreateInstanceTask.call(COM4J.java:117)
    at com4j.COM4J$CreateInstanceTask.call(COM4J.java:104)
    at com4j.Task.invoke(Task.java:51)
    at com4j.ComThread.run0(ComThread.java:153)
    at com4j.ComThread.run(ComThread.java:134)

2 个答案:

答案 0 :(得分:2)

OTAClient.dll是一个com组件,因此它需要在系统中注册以供使用(或者如果使用SxS则在清单中声明)。

您似乎缺少OTACLIENT.DLL本身或Webclient.dll的注册。

使用regsvr32命令行实用程序注册dll。

答案 1 :(得分:0)

尝试使用以下代码进行连接:

public static void main(String[] args) {    
   //QC url
   String url = "http://101.147.167.201:8081/qcbin";
   //username for login
   String username = "username";
   //password for login
   String password = "password";
   //domain
   String domain = "domian name";
   //project
   String project = "project name";
   ITDConnection connection = ClassFactory.createTDConnection();
   connection.initConnectionEx(url);
   connection.connectProjectEx(domain, project, username, password);
}