Go Back   ZeroC Forums > Help Center

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 05-16-2007
Djaunl 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
Reply With Quote
  #2 (permalink)  
Old 05-17-2007
benoit's Avatar
benoit benoit is online now
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,921
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.
Reply With Quote
  #3 (permalink)  
Old 05-17-2007
Djaunl 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
Reply With Quote
  #4 (permalink)  
Old 05-17-2007
benoit's Avatar
benoit benoit is online now
ZeroC Staff
 
Name: Benoit Foucher
Organization: ZeroC, Inc.
Project: Ice
 
Join Date: Feb 2003
Location: Rennes, France
Posts: 1,921
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.
Reply With Quote
  #5 (permalink)  
Old 05-18-2007
Djaunl 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.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using config file with Java client Djaunl Help Center 2 03-15-2007 02:43 PM
config file properties Greenhippo Help Center 3 01-16-2007 03:07 AM
Program implementation / File Transfer Questions (yes, i have read the faq :) )/ Ruby EmmanuelOga Help Center 2 08-01-2006 05:58 PM
Do 'setProperty' really set value to config file? kemp Help Center 2 07-22-2005 05:46 AM
set config properties w/o config file dkey Help Center 3 05-08-2005 05:27 AM


All times are GMT -4. The time now is 08:03 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0
(c) 2009 ZeroC, Inc.