Reputation: 6373
I have a spring boot application with embedded Tomcat that I'm testing through Netbeans. Under the directory src/main/resources/ I have two folders which contain static files. I'm trying to use those files but the program seems to think the folders are empty.
Here is some code I wrote to test the directories and see whether or not they contain any files.
pathToFiles = "/resources/";
if(true)
{
File kmlDirectory = new File(pathToFiles + "waitingKML/");
Collection<File> files;
files = FileUtils.listFiles(
kmlDirectory,
new RegexFileFilter("^(.*?)"),
DirectoryFileFilter.DIRECTORY
);
if(files.isEmpty()) {
return "Files are empty: " + kmlDirectory.toString();
}
else
return "Files are NOT empty";
}
And here is a picture of my directory structure (viewed from Netbeans).
When I run this test code I get 'Files are empty: \resources\waitingKML'.
According to documentation found here, https://spring.io/blog/2013/12/19/serving-static-web-content-with-spring-boot, Spring Boot will automatically add static web resources located within any of the following directories:
I'm wondering if this has to do with any property files or my configuration/setup?
Upvotes: 0
Views: 1579
Reputation: 1413
It's all dependent on what the programs current working directory is. Often in an IDE, it's going to be the root of your project, not src/main, so it can't find it.
Once it's a deployed WAR, you need to ensure resources are packaged correctly (can't tell what you're using to package everything up) and instead of raw file access need to use something like ClassLoader.getResourceAsStream() to get the static files
Upvotes: 1