有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java组织。天啊。科尔巴。包裹。InvalidName:IDL:omg。org/CORBA/ORB/InvalidName:1.0

您好,我正在尝试在eclipse上使用CORBA创建一个桌面应用程序。当我执行服务器类main时,我得到了以下错误,尽管我已经导入了corba和jcorb的API:

INFO Initialising ORB with ID: 
INFO InterceptorManager started with 0 Server Interceptors, 0 Client Interceptors and 1 IOR    Interceptors
INFO oid: 00 01 32 39 36 19 1F 2A 35 10 06 30 46 38 14 14 1B 48 4C 1B ..296..*5..0F8...HL.object is activated
INFO Using server ID (3169780447) for transient POA
org.omg.CORBA.ORBPackage.InvalidName: IDL:omg.org/CORBA/ORB/InvalidName:1.0
at org.jacorb.orb.ORB.resolve_initial_references(ORB.java:1608)
at main.SraCorbaServer.main(SraCorbaServer.java:50)

这是下面显示的服务器类主代码:

package main;
import org.omg.CORBA.ORB;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;   
import org.omg.CosNaming.NamingContextHelper;

public class SraCorbaServer {

public static void main(String[] args) {
    
    try {
    /   // Initialisation de l'ORB
        ORB orb = ORB.init(args, null);

        // Récupérer la référence du RootPOA et activer le POAManager
        POA rootpoa = (POA) POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        rootpoa.the_POAManager().activate();

        // Créer un servant (instance de classe d'implémentation) et l'enregistrer avec l'ORB
       SraCorbaImpl sci = new SraCorbaImpl();


        /* *** DEBUT INHERITANCE MODEL (vous pouvez vous référer aux chapitres précédents pour utiliser le modèle Tie Delegation Model) *** */

        // Récupérer une référence du servant
        org.omg.CORBA.Object servantRef = rootpoa.servant_to_reference(sci);

        SraCorba sc = SraCorbaHelper.narrow(servantRef);

        /* *** FIN INHERITANCE MODEL *** */

        // Récupérer la référence du service de nommage
        org.omg.CORBA.Object nsRef = orb.resolve_initial_references("NameService");
        NamingContextExt nce = NamingContextExtHelper.narrow(nsRef);

        // Créer un nom pour le service et ajouter le service
        String serviceName = "NameService";
        NameComponent nc[] = nce.to_name(serviceName);
        nce.rebind(nc, servantRef);

        // Démarrer le service et attendre les requêtes des clients
        System.out.println("On traite les requêtes des clients ...");
        orb.run(); 
}catch(Exception e) {
    e.printStackTrace();
}
}


}

**谢谢你帮助我:D**


共 (1) 个答案

  1. # 1 楼答案

    试试看:

    try{
            Properties props = new Properties();
            props.put("org.omg.CORBA.ORBInitialHost","localhost");
            props.put("org.omg.CORBA.ORBInitialPort","4321");
            ORB orb = ORB.init(args,props);
            SraCorbaImpl od = new SraCorbaImpl();
            POA rootPOA = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
            byte[] id = rootPOA.activate_object(od);
            org.omg.CORBA.Object ref = rootPOA.id_to_reference(id);
            String ior = orb.object_to_string(ref);
            System.out.println(ior);
            rootPOA.the_POAManager().activate();
            org.omg.CORBA.Object o = orb.resolve_initial_references("NameService");
            NamingContextExt context = NamingContextExtHelper.narrow(o);
            NamingContext newContext = context.new_context();
            NameComponent[] ctxName = context.to_name("TEST1");
            try {
                context.bind_context(ctxName,newContext);
            } catch(AlreadyBound e) {
                newContext = NamingContextHelper.narrow(context.resolve(ctxName));
            }
            newContext.rebind(context.to_name("B"),ref);
            System.out.println("Server running !");
            orb.run();
        }catch(Exception e){
            e.printStackTrace();
        }
    

    在这个例子中要小心,我将端口初始化为4321,所以在启动tnameserv时添加这个选项:tnameserv-ORBInitialPort 4321