Petr Lohonka:
Hi Vaadin:)
I am working with Vaadin 14 with Spring boot and I have problem with trying to reach directory with sounds in resources as a File class.
File soundsDir = new File(SOUNDS_DIRECTORY); // creating file with directory path - what should I put instead of SOUNDS_DIRECTORY variable?
File[] soundFiles = soundsDir.listFiles(); // soundfiles is null because no directory is found
if (soundFiles != null) {
for (File oneSoundFile : soundFiles) {
// do something with each file in directory
}
}
Path of java class = /src/main/java/ui/utils/SoundLibrary.java
Path of sounds directory = /src/main/resources/static/frontend/sounds
Only moment it worked was, when I hardcoded path to the directory on my local to try it. I tried almost everything, even ServletUtils from [How to get the Absolute Path in Vaadin 10 ]
(https://vaadin.com/forum/thread/17283562/how-to-get-the-absolute-path-in-vaadin-10), but nothing helped…
Weird is, that when I try getElement().setProperty("src", "./frontend/sounds/example.mp3"); on one Sound (private class in SoundLibrary), it works.
Thanks,
Petr
Hi Petr,
How about store directory path into springboot application.properties.
You can try set “SOUND_DIRECTORY” into your application.properties like below:
file.sound-dir=/home/someuser/somefolder/somesound
then you inject that properties into your java bean. I’ve also attached sample.
Best Regards,
Reja
Petr Lohonka:
Hi reja,
really thank you for your answer. But my problem is not how to inject it to Java bean, but WHAT to inject to java bean.
If I would use your example, what path (what string) exactly in my case I should put to
file.sound-dir=??????????
if directory, where should point file.sound-dir is on path /src/main/resources/static/frontend/sounds.
What string would you exactly write in application.properties for my case?
I just don’t know, how to reach path /src/main/resources/static/frontend/sounds (if I put there simply this string, it doesn’t work).
Hi Petr,
I see other similarity sample, but in directory "/src/main/resources/META-INF/resources/"
You can see the sample from below link. (Section “Resource Cheat Sheet” - Table 2. Spring projects)
https://vaadin.com/docs/v14/flow/importing-dependencies/tutorial-ways-of-importing.html
Hope this help.
Best Regards,
Reja