aspose file tools*
The moose likes I/O and Streams and the fly likes unable to load property file at runtime Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "unable to load property file at runtime" Watch "unable to load property file at runtime" New topic
Author

unable to load property file at runtime

Owais Zahid
Greenhorn

Joined: Nov 11, 2009
Posts: 21
Hi , i am a java beginner. My Jar file , has the following structure:

MyJar
|
sysProp.propertise
|
MyFolder
|
MySubFolder
|
main.class

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

In my main class, i am trying to load property file like this :

main.class.getResource("sysProp.propertise");

This is not working. Please tell me what code is needed to load the property file.

Please help.
Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
'It is not working' ist not a valid problem description. Are there by chance any exceptions thrown?


This code prints something like jar:file:/E:/Workspace/SomeProject/lib/somelib.jar!/some.file on my system. You can see the path within the jar file (it's directly under root, no subfolder inside the jar). If you'd like to read from a subfolder, you'd have to call something like


Censorship is the younger of two shameful sisters, the older one bears the name inquisition.
-- Johann Nepomuk Nestroy
Owais Zahid
Greenhorn

Joined: Nov 11, 2009
Posts: 21
URL result is NULL.

The property file is there in the jar file. I have checked it by un-jar the file. Is there any issue of loading the file from inner folders? My main file is in the Folder

MyFolder\MySubFolder\main.java

Peter Taucher
Ranch Hand

Joined: Nov 18, 2006
Posts: 174
And you're sure the JAR file is in your classpath? And you're sure you spelled your folder hierarchy and filename correctly?
damodar kumar
Ranch Hand

Joined: May 19, 2008
Posts: 77

Please check the path of the file

Please see the below example



main class have to search the file by comming back to two subfolders

so path would be ..//..//sysProp.propertise


<a href="http://stackoverflow.com/users/668970/user668970" rel="nofollow">
<img src="http://stackoverflow.com/users/flair/668970.png" >
</a>
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19722
    
  20

Or just "/sysProp.properties". Using ClassLoader.getResource(AsStream) the path is always relative to the root of the JAR file. Using Class.getResource(AsStream) the path is always relative to the class file itself, unless if it starts with a /.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to load property file at runtime