This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes ClassLoader.getSystemResourceAsStream() returning null Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "ClassLoader.getSystemResourceAsStream() returning null" Watch "ClassLoader.getSystemResourceAsStream() returning null" New topic
Author

ClassLoader.getSystemResourceAsStream() returning null

mahavir swami
Greenhorn

Joined: Sep 18, 2009
Posts: 13
I am using eclipse ide for my java projects
and in eclipse there is an option to export the project as a runnable jar file
and it creates MINIFEST.MF file which has all the information about the main method and other jar's used by the code

and in my code i am using


now when i run my code using eclipse , it finds abc.properties file
but when i am running through command prompt
java -jar <jar-file-name> args




returns null

now i believe there is some class path problem
i have set the classpath in my environmental variables but still cannot find above file from class path

please help

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38087
    
  22
Don't set the classpath as an environment variable.

Make sure the file is in the correct location. You will have a current directory, where you can invoke your classes with

java foo.bar.MyClassWithMainMethod

That is the sort of "root" for your package structure. Try copying the file into that location and see whether that improves things. If that doesn't help, don't know, sorry.
mahavir swami
Greenhorn

Joined: Sep 18, 2009
Posts: 13
I moved my properties file at the level where META-INF folder is there in jar file and
my code worked, i mean ClassLoader could find the file there
but if i want the file to be any where on the machine and the path will be set in classpath
then how do we achive that?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ClassLoader.getSystemResourceAsStream() returning null
 
Similar Threads
getSystemResourceAsStream - Reg
Accessig the properties file from outside the jar file
Problem loading Properties file
reading config file from JAR file
adding a property file to a jar