• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

unable to read the properties file in my jar

 
Sriram Sharma
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unzip your jar.
Do you see the src folder ? Or does the hierarchy start with the com folder?
 
himanshu.harish agrawal
Ranch Hand
Posts: 47
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nice catch Maneesh !!!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic