Monday, March 10, 2014

Spring MVC Get file under WEB-INF or in any lib *.jar

Use Spring DefaultResourceLoader and Resource to read inside WEB-INF or any resources in a *.jar file.


  import org.springframework.core.io.DefaultResourceLoader;
  import org.springframework.core.io.Resource;

       public static void myFunction() throws IOException {
            final DefaultResourceLoader loader = new DefaultResourceLoader();

            LOGGER.info(loader.getResource(
                  "classpath:META-INF/resources/img/copyright.png").exists());

            Resource resource = loader.getResource( 
                  "classpath:META-INF/resources/img/copyright.png");

            BufferedImage watermarkImage = ImageIO.read(resource.getFile());


        }

No comments:

False fear

There is a figure they said She talks to me It's a mischievous voice I can't deny that love They say she is pretty Smart and wa...