gpt4 book ai didi

java - 如何从属性文件初始化 ORB?

转载 作者:行者123 更新时间:2023-12-04 05:26:14 25 4
gpt4 key购买 nike

我想从属性文件初始化我的 ORB(通常我像这样初始化它,同时运行我的示例: ./app -ORBInitRef NameService=corbaloc::localhost:2809/NameService )

我写了一个简单的代码:

private static String[] readConfigFile()
{
Properties prop = new Properties();
String arg[] = new String[1];
try
{
prop.load(new FileInputStream("config.properties"));
} catch (IOException ex) {}
arg[0] = prop.getProperty("ORBInitRef");
return arg;
}

然后尝试初始化我的球体:
clientsORB = org.omg.CORBA.ORB.init(readConfigFile(), null);

但有一些错误:
2012-11-01 12:15:36 com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl <init>
WARNING: "IOP00410201: (COMM_FAILURE) Connection failure: socketType: IIOP_CLEAR_TEXT; hostname: 127.0.1.1; port: 900"
org.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No
at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2172)
at com.sun.corba.se.impl.logging.ORBUtilSystemException.connectFailure(ORBUtilSystemException.java:2193)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:223)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:236)
at com.sun.corba.se.impl.transport.SocketOrChannelContactInfoImpl.createConnection(SocketOrChannelContactInfoImpl.java:119)
at com.sun.corba.se.impl.protocol.CorbaClientRequestDispatcherImpl.beginRequest(CorbaClientRequestDispatcherImpl.java:168)
at com.sun.corba.se.impl.protocol.CorbaClientDelegateImpl.request(CorbaClientDelegateImpl.java:136)
at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.invoke(BootstrapResolverImpl.java:99)
at com.sun.corba.se.impl.resolver.BootstrapResolverImpl.resolve(BootstrapResolverImpl.java:132)
at com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.java:47)
at com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.java:47)
at com.sun.corba.se.impl.resolver.CompositeResolverImpl.resolve(CompositeResolverImpl.java:47)
at com.sun.corba.se.impl.orb.ORBImpl.resolve_initial_references(ORBImpl.java:1174)
at ClientConnection.connect(ClientConnection.java:68)
at Client.main(Client.java:303)
Caused by: java.net.ConnectException: Connection refused
at sun.nio.ch.Net.connect(Native Method)
at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:525)
at java.nio.channels.SocketChannel.open(SocketChannel.java:164)
at com.sun.corba.se.impl.transport.DefaultSocketFactoryImpl.createSocket(DefaultSocketFactoryImpl.java:78)
at com.sun.corba.se.impl.transport.SocketOrChannelConnectionImpl.<init>(SocketOrChannelConnectionImpl.java:206)
... 12 more

我的 config.properties 文件:
ORBInitRef NameService=corbaloc::localhost:2809/NameService
我做错了什么? 当我正常初始化我的 ORB 时,一切都很好,所以这不是代码问题,它绝对是从文件初始化的问题。

最佳答案

您必须添加 -ORBInitRef也到 ORB 参数。将它与您通常使用的命令行进行比较。所有参数都必须传递给 ORB.init()
config.properties:

ORBInitRef NameService=corbaloc::localhost:2809/NameService 

使用它的 Java 代码 (ReadProps.java)
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

import org.omg.CORBA.ORB;

public class ReadProps {
public static void main(String[] args) {
ORB clientsORB = org.omg.CORBA.ORB.init(readConfigFile(), null);
}

static String[] readConfigFile() {
Properties prop = new Properties();
String[] orbarg = new String[2];

try {
// load a properties file
prop.load(new FileInputStream("config.properties"));
// get the property value and print it out
orbarg[0] = "-ORBInitRef"; // <---- NEEDED
orbarg[1] = prop.getProperty("ORBInitRef");

} catch (IOException ex) {
ex.printStackTrace();
}
return orbarg;
}

}

关于java - 如何从属性文件初始化 ORB?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13175907/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com