aspose file tools*
The moose likes Java in General and the fly likes unable to read the properties file in my jar Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "unable to read the properties file in my jar" Watch "unable to read the properties file in my jar" New topic
Author

unable to read the properties file in my jar

Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 98
Hi All,

I am trying to execute a jar file from command prompt.
It is a swing application that i created through Netbeans.
In my application I have a location "src/com/java/db/properties" which contains my properties file.
Now, my code snippet for loiading the properties file goes here below...



When I run my app through the netbeans, this works fine.
But when I execute it using my jar through command prompt, I get an error saying



Now, when I changed my code snippet to the following...



And by doing this I get null pointer exception at props.load(in).
This is because "in" is "null" and I dont know the reason for it to be null.
Can any of you help me on this???
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10535
    
    9

Unzip your jar.
Do you see the src folder ? Or does the hierarchy start with the com folder?


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
himanshu.harish agrawal
Ranch Hand

Joined: Oct 18, 2010
Posts: 47

I am not sure about success but you can try out below things.

For your case1:
it is giving FileNotFoundException when running through command line because it is able to find the source. Try adding XXX/src, where XXX is the root diredctory, in your source path from command line argument "-sourcepath". Netbeans is doing this thing for you that is why no issue there.

For your case2:
JVM will also load resource from your context path. So, package the properties file in directly under your JAR, i mean not under any folder, and it will then not give an null pointer.

Thanks.
Sriram Sharma
Ranch Hand

Joined: Apr 12, 2006
Posts: 98
Thanks a lot Maneesh!
When I unzipped, the folder structure was "com\java\db\properties"
This was really the exact mistake and thanks for pointint it out...
So silly of me :-p

Thanks to you too Himanshu!!! :-)

Thanks again guys... :-)

Regards,
Sriram
himanshu.harish agrawal
Ranch Hand

Joined: Oct 18, 2010
Posts: 47

nice catch Maneesh !!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: unable to read the properties file in my jar