Can't find resource 'frontend://my-view.html'

V14 Compatabilty mode OSGi running in Karaf 4.3.0, My directory layout is attached.

As far as I can tell I have done all that is necessary to use the output from designer to create a view.

Any ideas of what I am doing wrong?

Servlet

@Component(immediate = true)
public class QServletRegistration {

    @Reference
    QUIManager uiManager;

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////// Activate ///////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    @Activate
    void activate(BundleContext ctx) {
        Hashtable<String, Object> properties = new Hashtable<>();
        properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_ASYNC_SUPPORTED, true);
        properties.put(HttpWhiteboardConstants.HTTP_WHITEBOARD_SERVLET_PATTERN, "/*");
        QVaadinServlet vaadinServlet = new QVaadinServlet();
        vaadinServlet.setUIManager(uiManager);
        ctx.registerService(Servlet.class, vaadinServlet, properties);
    }

public class QVaadinServlet extends VaadinServlet {

    private QUIManager uiManager;

    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        super.init(servletConfig);
        getService().setClassLoader(getClass().getClassLoader());
    }

    @Override
    protected DeploymentConfiguration createDeploymentConfiguration(Properties initParameters) {
        // npm mode is not currently supported
        initParameters.setProperty("compatibilityMode", "true");
        return super.createDeploymentConfiguration(initParameters);
    }

OSGi resources

        return Arrays.asList(
                OsgiVaadinStaticResource.create(
                        "/META-INF/resources/frontend/styles/shared-styles.html",
                        "/frontend/styles/shared-styles.html"),
                OsgiVaadinStaticResource.create(
                        "/META-INF/resources/frontend/my-view.html",
                        "/frontend/frontend/my-view.html"),

MyView Java

@Tag("my-view")
@HtmlImport("my-view.html")
@Route("")
public class MyView extends PolymerTemplate<MyView.MyViewModel> {

    @Id("testBtn")
    private Button testBtn;

    /**
     * Creates a new MyView.
     */
    public MyView() {
        testBtn.addClickListener(click -> {
            Notification.show("Click");
        });
    }

    /**
     * This model binds properties between MyView and my-view
     */
    public interface MyViewModel extends TemplateModel {
        // Add setters and getters for template properties here.
    }
}

Error

There was an exception while trying to navigate to '' with the exception message 'Unable to create an instance of 'net.qnenet.qne.qwebsite.provider.views.designer.MyView'. The constructor threw an exception.'

java.lang.IllegalArgumentException: Unable to create an instance of 'net.qnenet.qne.qwebsite.provider.views.designer.MyView'. The constructor threw an exception.
	at com.vaadin.flow.internal.ReflectTools.createProxyInstance(ReflectTools.java:512)
	at com.vaadin.flow.internal.ReflectTools.createInstance(ReflectTools.java:449)
	at com.vaadin.flow.di.DefaultInstantiator.create(DefaultInstantiator.java:137)
	at com.vaadin.flow.di.DefaultInstantiator.getOrCreate(DefaultInstantiator.java:66)
	at net.qnenet.qne.qwebsite.provider.osgi.QInstantiator.createRouteTarget(QInstantiator.java:35)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.lambda$getRouteTarget$1(AbstractNavigationStateRenderer.java:135)
	at java.base/java.util.Optional.orElseGet(Optional.java:369)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.getRouteTarget(AbstractNavigationStateRenderer.java:134)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.sendBeforeEnterEventAndPopulateChain(AbstractNavigationStateRenderer.java:518)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.createChainIfEmptyAndExecuteBeforeEnterNavigation(AbstractNavigationStateRenderer.java:498)
	at com.vaadin.flow.router.internal.AbstractNavigationStateRenderer.handle(AbstractNavigationStateRenderer.java:230)
	at com.vaadin.flow.router.Router.handleNavigation(Router.java:249)
	at com.vaadin.flow.router.Router.navigate(Router.java:220)
	at com.vaadin.flow.router.Router.navigate(Router.java:186)
	at com.vaadin.flow.router.Router.initializeUI(Router.java:93)
	at com.vaadin.flow.server.BootstrapHandler.createAndInitUI(BootstrapHandler.java:1534)
	at com.vaadin.flow.server.BootstrapHandler.synchronizedHandleRequest(BootstrapHandler.java:474)
	at com.vaadin.flow.server.SynchronizedRequestHandler.handleRequest(SynchronizedRequestHandler.java:40)
	at com.vaadin.flow.server.VaadinService.handleRequest(VaadinService.java:1545)
	at com.vaadin.flow.server.VaadinServlet.service(VaadinServlet.java:247)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
	at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1651)
	at org.eclipse.jetty.websocket.server.WebSocketUpgradeFilter.doFilter(WebSocketUpgradeFilter.java:226)
	at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1638)
	at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:567)
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceServletHandler.doHandle(HttpServiceServletHandler.java:71)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
	at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
	at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
	at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1377)
	at org.ops4j.pax.web.service.jetty.internal.HttpServiceContext.doHandle(HttpServiceContext.java:294)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
	at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:507)
	at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
	at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
	at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1292)
	at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
	at org.ops4j.pax.web.service.jetty.internal.JettyServerHandlerCollection.handle(JettyServerHandlerCollection.java:82)
	at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
	at org.eclipse.jetty.server.Server.handle(Server.java:501)
	at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
	at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
	at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
	at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
	at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
	at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:105)
	at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
	at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
	at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
	at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
	at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
	at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
	at com.vaadin.flow.internal.ReflectTools.createProxyInstance(ReflectTools.java:481)
	... 58 more
Caused by: java.lang.IllegalStateException: Can't find resource 'frontend://my-view.html' via the servlet context
	at com.vaadin.flow.component.polymertemplate.DefaultTemplateParser.getTemplateContent(DefaultTemplateParser.java:103)
	at com.vaadin.flow.component.polymertemplate.TemplateDataAnalyzer.parseTemplate(TemplateDataAnalyzer.java:200)
	at com.vaadin.flow.component.polymertemplate.TemplateInitializer.<init>(TemplateInitializer.java:91)
	at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:88)
	at com.vaadin.flow.component.polymertemplate.PolymerTemplate.<init>(PolymerTemplate.java:103)
	at net.qnenet.qne.qwebsite.provider.views.designer.MyView.<init>(MyView.java:29)
	... 63 more

18485063.png

As you can see the exception says that the resource frontend://my-view.html is not found.
Which mean the resource is not available in the servlet context.

I didn’t get how you registered OsgiVaadinStaticResource since there is only a code snippet but it doesn’t matter at the moment.

The exception is about absence of the resource in the servlet context , not in the web.
The template is parsed inside Flow and to be able to do that the resource is accessed via ServletContext::getResource.

So for some reasons the ServletContext doesn’t know about the resource.

So please make sure that my-view.html is in the bundle with location which ServletContext may access.

I don’t recall exact details but most likely you should put my-view.html into /frontend/my-view.html into the root of your bundle (may be in addition to the location which you use for the web or change the registration so that it refers to this path in root).

Thanks for replies, Denis,

These attached images indicate the situation which is causing the error.

The image with the Intellij info might give a clue.

I am getting a good result in my OSGi project (compatability mode) using normal Vaadin components but due to this problem I am prevented from using designer and all the goodies that come with the html templates.

Can you see where I might be going wrong?

18496703.png
18496706.png

I think I do.
As I understand your resources are inside META-INF.
META-INF resources are never available in the web (they are protected) unless you explicitly make them available somehow.

As I said: the resources have to be available via the ServletContext. Resources in the META-INF are not available via ServletContext.

As said: put your resources inside the ROOT of your jar file (may be in the frontend directory).
This way you don’t even need to register them via OsgiVaadinStaticResource.

Actually : this is only for Polymer template resources.
OsgiVaadinStaticResource can be used only for resources which need to be available when you request them via HTTP .
But as said: templates are parsed and ServletContext is used to access to them. If you put the resources in the root then they will be available via HTTP without OsgiVaadinStaticResource: you may remove your OsgiVaadinStaticResource and check whether they are available or not. This can be an indicator.

Alternatively you may register a servlet via HTTP whiteboard spec and use ServletContextHelper : then you may implement the access to the resources there by yourself.