Results 1 to 5 of 5

Thread: Cannot read config file using Java ClassLoader

  1. #1
    Djaunl is offline Registered User
    Name: Dan Gresh
    Organization: LLE
    Project: EP control systems
    Join Date
    Mar 2007
    Posts
    15

    Cannot read config file using Java ClassLoader

    Hey,

    I've packaged the configuration file for my ICE client, nvacconfig, into a JAR file, at the path config/nvacconfig. I can load this config file normally using Ice.InitializationData.properties.load(String file), but I cannot do that from inside my JAR; I need to use a ClassLoader to read the file.

    Seeing as InitializationData.properties.load() only takes a String argument, I cannot pass the file as an InputStream, which is what I would normally do:
    Code:
    		ClassLoader cl = this.getClass().getClassLoader();
    		InputStream file = cl.getResourceAsStream("config/nvacconfig");
    		Ice.InitializationData id;
    		try {
    		    id = new Ice.InitializationData();
    		    id.properties = Ice.Util.createProperties();
    		    id.properties.load(file);
                        // Does not work
    Also, I cannot use java.net.URL to load the appropriate file and pass it as a String; it will not read the file correctly.

    Is there a way to load this configuration file properly to the InitializationData using a ClassLoader? Is there another way to load this configuration file?

    Thanks,
    Dan

  2. #2
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,140
    Hi,

    No it's currently not possible to automatically load the configuration file from the Jar file (so you'll have to load the configuration file yourself and setup the properties "manually"). If you would like this feature to be added to Ice, please contact us at info@zeroc.com.

    Cheers,
    Benoit.

  3. #3
    Djaunl is offline Registered User
    Name: Dan Gresh
    Organization: LLE
    Project: EP control systems
    Join Date
    Mar 2007
    Posts
    15
    Hello,

    Thanks for the reply. I am a bit lost however as to how to setup the properties from the configuration file manually.

    I altered my Ice.Communicator.stringToProxy calls by simply hard-coding the appropriate information, such as:

    Code:
    base = NVACMain.getIC().stringToProxy("IceStorm/TopicManager:tcp -p port -h localhost");
    The only problem I have remaining is the IceGrid Locator service. I am unsure of how to load this manually. I used to load it in the config file, but I can't anymore. I've tried passing it to Ice.Communicator.initialize, as if I were specifying it from the command line, but that has not worked either.

    I've tried using three different arguments, none of which have worked correctly:

    Code:
    		String[] argv = {"Ice.Default.Locator=IceGrid/Locator:default -h localhost -p port",
    			"IceGrid/Locator:default -h localhost -p port",
    			"--IceGrid/Locator:default -h localhost -p port"};
    		try {
    			ic = Ice.Util.initialize(argv);
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    Obviously, this either cannot be done, or the syntax is wrong (I guessed on the syntax, as I couldn't find anything about doing this in the documentation).

    I am positive the problem lies in the IceGrid Locator, as I was not registering any events from IceStorm without loading the config file, even if I specified the appropriate proxies and topicnames.

    Is there a way to do what I am trying to do? Can I manually specify the IceGrid Locator information? Is there another way I can go about doing this?

    Thanks,
    Dan

  4. #4
    benoit's Avatar
    benoit is offline ZeroC Staff
    Name: Benoit Foucher
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Rennes, France
    Posts
    2,140
    The command line argument should be: "--Ice.Defaut.Locator=IceGrid/Locator:default -h localhost -p port".

    That's not exactly what I was suggesting though. I was suggesting to set the properties manually with "Ice::Properties::setProperty()" prior to the communicator initialization (with values obtained from the configuration file stored in the Jar file, you would take care of the parsing of this configuration file.)

    Something like the following:

    Code:
       String locator = ... // get the locator setting from your configuration file.
       InitializationData initData = new Ice.InitializationData();
       initData.properties = Ice.Util.createProperties();
       initData.properties.setProperty("Ice.Default.Locator", locator);
    Cheers,
    Benoit.

  5. #5
    Djaunl is offline Registered User
    Name: Dan Gresh
    Organization: LLE
    Project: EP control systems
    Join Date
    Mar 2007
    Posts
    15
    Ah, I see now what you mean. This works fine now, thanks a lot.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to use my config file in VS 2005
    By bxhsix in forum Help Center
    Replies: 2
    Last Post: 03-30-2008, 04:46 AM
  2. Using config file with Java client
    By Djaunl in forum Help Center
    Replies: 2
    Last Post: 03-15-2007, 03:43 PM
  3. config file properties
    By Greenhippo in forum Help Center
    Replies: 3
    Last Post: 01-16-2007, 04:07 AM
  4. Replies: 2
    Last Post: 08-01-2006, 06:58 PM
  5. set config properties w/o config file
    By dkey in forum Help Center
    Replies: 3
    Last Post: 05-08-2005, 06:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •