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???
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.
posted 9 years ago
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