• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

unable to read the properties file in my jar

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unzip your jar.
Do you see the src folder ? Or does the hierarchy start with the com folder?
 
Ranch Hand
Posts: 47
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
nice catch Maneesh !!!
 
reply
    Bookmark Topic Watch Topic
  • New Topic