• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Resource loading from system file path VS classpath

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any opinions on the same?I am still looking for some replies.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic