aspose file tools*
The moose likes Beginning Java and the fly likes Unable to load a .properties file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Unable to load a .properties file" Watch "Unable to load a .properties file" New topic
Author

Unable to load a .properties file

James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
I have a .properties file I want to load but I always get a FileNotFoundException. Below is the code where the problem happens:





The file I want to load my Properties from, Ilx.properties, is located in the deployment directory for my JBoss application. For example

JBOSS_HOME/server/default/deploy/myapp.sar/Ilx.properties


There doesn't seem to be a difference when this file is in the META-INF directory, it still is not found. Also when I specify the complete path name for the file I still get the exception. For example the following doesn't work either:




Any suggestions on what I can do in order to make this file visible to JBoss ?

Thanks in advance...


--James
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
You might be able to use 'class_name.getClassLoader().getResource(file_name)' to do this... whether this works may depend on the file location.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


whether this works may depend on the file location.


depends on the classpath actually.



just put the file somewhere on the classpath and it will be picked up.

ram.
James Adams
Ranch Hand

Joined: Sep 12, 2003
Posts: 188
Unfortunately this isn't working for me. I'm now getting a NullPointerException instead of the FileNotFoundException as before, so it now seems to at least be finding the .properties file OK.

I have added the directory where the properties file is living (c:\jboss\jboss-4.0.1\server\ilxupgrade\deploy\500ilxupgrade.sar) to the JBOSS_CLASSPATH used in the JBoss run.sh, as well as to the CLASSPATH environment variable for good measure. When I run JBoss using the run.sh command I see the following listing of paths being used:




I have added the suggested code above:




My .properties file looks like this:




In my loadProperties() method it is the Properties.load() call where the NullPointerException is happening, but it doesn't make sense since the InputStream I'm using is successfully created with my .properties filename and hence is not null (I've checked). What else could be null and causing the exception ?


--James
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

Hope u have initialized the m_ilxMsgProperties Properties object (just sanity checking :-)).
Can u print the stack trace.
Also u have said

I have added the directory where the properties file is living (c:\jboss\jboss-4.0.1\server\ilxupgrade\deploy\500ilxupgrade.sar) to the JBOSS_CLASSPATH used in the JBoss run.sh, as well as to the CLASSPATH environment variable for good measure.

isnt 500ilxupgrade.sar a file ? is it a directory ? i ask bcos u have said ur props file is located there. But it shouldnt be a problem bcos u mentioned later that the InputStream object is suceesfully created. Can u do a System.out.println(InputSteamObject.toString()) before u call load ? That will cnsure that the null pointer is not on the InputStream object. My take is if the stream is loaded properly, then the load() method should work. Anyways pls post ur stack trace.

ram.
ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489


--------------------------------------------------------------------------------

I have added the directory where the properties file is living (c:\jboss\jboss-4.0.1\server\ilxupgrade\deploy\500ilxupgrade.sar) to the JBOSS_CLASSPATH used in the JBoss run.sh, as well as to the CLASSPATH environment variable for good measure.

--------------------------------------------------------------------------------


isnt 500ilxupgrade.sar a file ? is it a directory ? i ask bcos u have said ur props file is located there



is ur props file in the deploy directory ? it should be there, shouldnt it ?
so ur cp has to be c:\jboss\jboss-4.0.1\server\ilxupgrade\deploy - right ?
pls chk.

ram.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to load a .properties file