start orbd -ORBInitialPort 1050 -ORBInitialHost localhost
start java HelloServer -ORBInitialPort 1050 -ORBInitialHost localhost
在用上面命令启动服务端时出现以下错误:
org.omg.CORBA.INITIALIZE: can't instantiate default ORB implementation IE.Iona.OrbixWeb.CORBA.ORB vmcid: 0x0 minor code: 0 completed: No
at org.omg.CORBA.ORB.create_impl(ORB.java:297)
at org.omg.CORBA.ORB.init(ORB.java:336)
at HelloServer.main(HelloServer.java:37)
Caused by: java.lang.ClassNotFoundException: IE.Iona.OrbixWeb.CORBA.ORB
at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:274)
at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:219)
at org.omg.CORBA.ORB.create_impl(ORB.java:295)
... 2 more
HelloServer Exiting...
//HelloServer.java
import HelloApp.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;
class HelloImpl extends HelloPOA {
private ORB orb;
public void setORB(ORB orb_val) {
orb = orb_val;
}
//implement sayHello() method
public String sayHello() {
return "\nHello World\n";
}
public void shutdown() {
orb.shutdown(false);
}
}
public class HelloServer {
public static void main(String[] args) {
try {
// create and initialize the ORB
ORB orb = ORB.init(args, null);
// get reference to rootpoa & activate the POAManager
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
// create servant and register it with the ORB
HelloImpl helloImpl = new HelloImpl();
helloImpl.setORB(orb);
// get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(helloImpl);
Hello href = HelloHelper.narrow(ref);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
// Use NamingContextExt which is part of the Interoperable
// Naming Service (INS) specification.
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
// bind the object Reference in Naming
String name = "Hello";
NameComponent path[] = ncRef.to_name(name);
ncRef.rebind(path, href);
System.out.println("HelloServer ready and waiting...");
// wait for invocations from clients
orb.run();
} catch (Exception err) {
System.err.println("ERROR:"+err);
err.printStackTrace(System.out);
}
System.out.println("HelloServer Exiting...");
}
}