VaadinService.getCurrent().getStaticResource() on initialization

Hi,

I’m new to Flow (using 14.0.0beta3), and I’m migrating my old V8 application to V14.

Among many others, I found a strange problem in a class of mine called AConstants, which is read when initializing the application.
It contains some strings whose value is assigned by VaadinService.getCurrent().getStaticResource(“/WEB-INF/MY_FILE_NAME”).toString().
MY_FILE_NAME exists in the final .war package, but it seems that Vaadin14 can’t find it.

Could it be some timing issue, i.e.: VaadinService.getCurrent().getStaticResource() being called “too early” in the initialization stage?
BTW, this was not an issue in Vaadin8.

Thanks,
MZ

Hi.

When requesting for resources through VaadinService.getCurrent().getStaticResource(...) the resource is served from the servlet context getServletContext().getResource(path). So as long as the WEB-INF/my-file is in the correct place as with Vaadin 8 it should be found by the server.

At least for my test case with the base starter having the file src/main/webapp/WEB-INF/My-txt.txt running through maven or on tomcat 9 from a war the resource was found using VaadinService.getCurrent().getStaticResource("/WEB-INF/My-txt.txt") on MainView construction.

Where are you trying to find the resource at?
I would expect it to be available at any time that you can run application code in.

  • Mikael

Hi Mikael, and thanks for Your reply.

Turned out it was a silly mistake by me (that’s the bad side of working late): the new method VaadinService.getCurrent().getStaticResource() returns a URL, not a String like the old VaadinService.getCurrent().getBaseDirectory().toString().

I decided to re-implement the old “getBaseDirectory” as shown here: https://vaadin.com/forum/thread/17283562/how-to-get-the-absolute-path-in-vaadin-10.

Thanks (and apologies),
MZ

Hi.

Good that the issue was solved. Also these things happen and sometimes it’s easier to have a sounding board to notice simple issues. =)

  • Mikael