When I create a jar library (say, a Vaadin add-on) and if I have some Polymer templates, where should I keep the resource files for my @HtmlImport?
I tried to put in a folder and specified @HtmlImport("frontend://folder/...") but it is not getting loaded.
Also tried: @HtmlImport("/folder/...")
(I confirm see that the file exists in my jar file)
If your template is in your local project, i.e. in “src/main/webapp/frontend” folder say like “src/main/webapp/frontend/my-template.html”, you can do just @HtmlImport(“my-template.html”)
However, if you have add-on that consist probably web jar where the actual template is, the template is put in different folder under “bower_components”, so then you should use something like @HtmlImport(“bower_components/my-add-on/my-add-on.html”)
The META-INF/resources folder in a JAR file corresponds to the src/main/webapp folder in a web app project. So if you use @HtmlImport("my.html") (it’s the same as @HtmlImport("frontend://my.html"), then the file in the jar should be META-INF/resources/frontend/my.html
Thank you Artur & Tatu.
Sorry, it’s not working.
I have in my jar file, the following entry: META-INF/resources/frontend/app-layout/app-layout.html
And, my import is as follows: @HtmlImport("frontend://app-layout/app-layout.html")
Also, tried: @HtmlImport("app-layout/app-layout.html")
I am getting the following exception:
Caused by: java.lang.IllegalStateException: Can't find resource 'frontend://app-layout/app-layout.html' via the servlet context
at com.vaadin.flow.component.polymertemplate.DefaultTemplateParser.getTemplateContent(DefaultTemplateParser.java:104)
at com.vaadin.flow.component.polymertemplate.TemplateDataAnalyzer.parseTemplate(TemplateDataAnalyzer.java:185)
at com.vaadin.flow.component.polymertemplate.TemplateInitializer.<init>(TemplateInitializer.java:93)
at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:97)
...