How to init ORB from property file?

后端 未结 1 1467
日久生厌
日久生厌 2021-01-21 12:57

I would like to init my ORB from property file (normally I init it like this, while running my examples: ./app -ORBInitRef NameService=corbaloc::localhost:2809/NameServic

1条回答
  •  有刺的猬
    2021-01-21 13:23

    You have to add -ORBInitRef to the ORB arguments also. Compare it to the commandline you normaly use. ALL the arguments have to be passed to the ORB.init()

    config.properties:

    ORBInitRef NameService=corbaloc::localhost:2809/NameService 
    

    Java Code using it (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;
        }
    
    }
    

    0 讨论(0)
提交回复
热议问题