go to  ForumEasy.com   
JavaPro
Home » Archive » Message


[Email To Friend][View in Live Context][prev topic « prev post | next post » next topic]
  Where should I put my resource file? -- resource folder
 
Subject: Where should I put my resource file? -- resource folder
Author: EricJ
In response to: getResource -- where should I put my resource file?
Posted on: 08/26/2013 06:04:19 PM

If you are a developer and you want to get the following instance generated correctly:

try{

    ehcache_manager = CacheManager.
                         create(this.getClass().getResourceAsStream("ehcache.xml"));

}catch(Exception e){
    e.printStackTrace();
}


the property file 'ehcache.xml' which is used to customize your ehcache should be put under:

   [+]---src
      [+]---org
         [+]---test
            [+]---example
               [-]---HelloEhcache.java

   [+]---resource
      [+]---org
         [+]---test
            [+]---example
               [-]---ehcache.xml


and include the resource folder as your source. After compilation, the resource files should be copied onto under classes folder together with source

files.
   [+]---classes
      [+]---org
         [+]---test
            [+]---example
               [-]---HelloEhcache.class
               [-]---ehcache.xml


You may want to use absolute path as:
try{

    ehcache_manager = CacheManager.
                         create(this.getClass().getResourceAsStream("/ehcache.xml"));

}catch(Exception e){
    e.printStackTrace();
}


the property file 'ehcache.xml' which is used to customize your ehcache should be put under:

   [+]---src
      [+]---org
         [+]---test
            [+]---example
               [-]---HelloEhcache.java

   [+]---resource
      [-]---ehcache.xml


 

> On 08/26/2013 06:02:18 PM EricJ wrote:

try{
    System.out.println(this.getClass().getResource("/").toURI().toString());
    System.out.println(this.getClass().getResource(".").toURI().toString());
}catch(Exception e){
    e.printStackTrace();
}


Output:
file:/C:/Users/test/workspace/p1/WebContent/WEB-INF/classes/
file:/C:/Users/test/workspace/p1/WebContent/WEB-INF/classes/org/test/example/ 






References:

 


 
Powered by ForumEasy © 2002-2022, All Rights Reserved. | Privacy Policy | Terms of Use
 
Get your own forum today. It's easy and free.