aspose file tools*
The moose likes Spring and the fly likes Resource loading from system file path VS classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Resource loading from system file path VS classpath" Watch "Resource loading from system file path VS classpath" New topic
Author

Resource loading from system file path VS classpath

Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
I understand that we can load a resource say an XML context definition file using the FileSysytemXmlApplicationContext or ClassPathXmlApplicationContext.While the former loads the resource from a system file location path, the latter does it by searching the classpath(even in Jar files).
Are there any pros and cons of these modes of resource loading?Isn't file system loading more faster as compared to searching on the classpath?
Should there be any considerations when developing our applications to load resources?
I understand that since loading of resources would be mostly at application startup, it should not be a major issue.But still is there any significance from the application point of view?
Nikhil Sun
Ranch Hand

Joined: Nov 13, 2005
Posts: 108
Any opinions on the same?I am still looking for some replies.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Nikhil Sun wrote:I understand that we can load a resource say an XML context definition file using the FileSysytemXmlApplicationContext or ClassPathXmlApplicationContext.While the former loads the resource from a system file location path, the latter does it by searching the classpath(even in Jar files).
Are there any pros and cons of these modes of resource loading?Isn't file system loading more faster as compared to searching on the classpath?
Should there be any considerations when developing our applications to load resources?
I understand that since loading of resources would be mostly at application startup, it should not be a major issue.But still is there any significance from the application point of view?


I guess for me it depends on whether the configuration file is in the jar/war/ear file. In that case I would use classpath, for war files I put it in the WEB-INF directory and use http: or XmlWebApplicationContext. Sometimes you are including a third party jar from someone else and the file is in the classpath, so in order to load it up, it has to be via classpath. Sometimes the file is outside the archive file and you have to use FileSystem.

In any case I always prefix all my locations with either "classpath:" "file:" or "http:" so that it doesn't matter which ApplicationContext version you use, it will always load the files based on the prefix.

Hope that helps clarify things for you

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Resource loading from system file path VS classpath