• Post Reply Bookmark Topic Watch Topic
  • New Topic

? load resources from a classpath folder(outside archive)  RSS feed

 
Chris Riffle
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

Is it possible to dynamically load a resource, like a java .properties file, when that file is just sitting by itself in a folder that's in the class path(such as a lib folder)? I'd like to get to it without stuffing it into a .jar and without hard-coding a disk path to it.
Thanks!

+Application
+src
-lib
here.properties
ArchivedResources.jar
+bin
[ September 12, 2008: Message edited by: Chris Riffle ]
 
Venkat Sadasivam
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not adviced to this way. Why don't you load through FileInputStream outside the classpath?
 
Rene Larsen
Ranch Hand
Posts: 1179
Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the *.properties file is located in the classpath of the application e.g. same folder as the *.class files, inside a jar-file or in a folder that is set up as part of the classpath - then you can read it by using the ResourceBundle or Properties class.

The Properties class can be initialized with an InputStream which you get by calling (if not from a static class)
If you need to initialize it from a static method/block you need to replace "this.getClass()" with the class name of the calling class e.g.
[ September 12, 2008: Message edited by: Rene Larsen ]
 
Chris Riffle
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rene,

I like the 3rd situation you mentioned where the example.properties file is located in a folder that's included in the class path(not in a .jar)

I did it this way:



where the example.properties file is located in a folder that's included in the classpath


[ September 12, 2008: Message edited by: Chris Riffle ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!