1

I have some files under the static folder. And after I deploy another version of war all my files under static folder get lost. Tomcat automatically removes the folder. Is there any way around to save the file?

I also try to build a project using springboot and make the static folder just outside the project. But I am unable to do that.

@Configuration
public class WebConfiguration extends WebMvcConfigurationSupport {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    String path = this.getClass().getClassLoader().getResource("").getPath();
    String fullPath="";
    try {
        fullPath = URLDecoder.decode(path, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    String pathArr[] = fullPath.split("jobportal/WEB-INF/classes/");
    File directory = new File(pathArr[0].concat("uploads"));
    if (!directory.exists()) {
        directory.mkdir();
    }
    String[] CLASSPATH_RESOURCE_LOCATIONS = {
            "classpath:/META-INF/resources/", "classpath:/resources/",
            "classpath:/static/", "classpath:/public/",directory.getAbsolutePath()};
    registry.addResourceHandler("/**")
    .addResourceLocations(CLASSPATH_RESOURCE_LOCATIONS);
    registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
    registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}
}

I have been using the above configurations. I am only able to serve static files inside the project not outside. Please Help.

Munal
  • 11
  • 3
  • save them outsite the tomcat folder :) – Leviand Aug 30 '18 at 08:08
  • You can find the answer at https://serverfault.com/questions/709066/tomcat-keeping-specific-files-when-deploying-a-war-file. Yah as @Leviand said, save them outside. – Gimhani Aug 30 '18 at 08:11
  • @Gimhani I have been trying to do that too. But don't know what I am doing wrong – Munal Aug 30 '18 at 08:13
  • @Leviand I am unable to figure what's going wrong – Munal Aug 30 '18 at 08:15
  • Possible duplicate of [Where/how to store persistent data with tomcat?](https://stackoverflow.com/questions/1792634/where-how-to-store-persistent-data-with-tomcat) – Olaf Kock Aug 30 '18 at 08:53

0 Answers0