Search This Blog

Featured

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: