New theme in a maven and jetty embedded application

In my Vaadin application I am using maven and an embedded jetty server, so my tree structure doesn’t follow the standard. Basically, under my web module I have a src folder with all the sources. Everything is working fine, the Vaadin repositories are imported by maven and I’m using Valo theme.
My problem is that I want to create my own theme now but I don’t know where to place it so Vaadin can find it.
The error I get:

Requested resource [/VAADIN/themes/mytheme/styles.css] not found from filesystem or through class loader. Add widgetset and/or theme JAR to your classpath or add files to WebContent/VAADIN folder. This is the configuration of the server:

WebAppContext appContext = new WebAppContext(); appContext.setContextPath("/"); appContext.setResourceBase("."); jetty.setHandler(appContext); ServletContextHandler servletHandler = new ServletContextHandler(jetty, "/dev", true, false); servletHandler.addServlet(servletHolder, "/Test/*"); servletHandler.addServlet(servletHolder, "/VAADIN/*"); I’ve tried to create a structure like this: VAADIN/themes/mytheme in the root of the module and many other options but I couldn’t get the new theme to work, because I don’t know where VAADIN is looking for the personalised themes. Or am I missing any configuration?

Thanks for the help

When using Maven, Vaadin usually looks for the theme in src/main/webapp/VAADIN/themes/

yep thanks, I have tried that location too with no luck

Do you think I should make maven pack the theme in the jar explicitly?

Yes, make sure it is available on the classpath as resource “/VAADIN/themes/mytheme/styles.css”.

__
m

Hi, I’ve been able to include my theme as a resource. Now I have a problem with the compilation of scss. This is the error I get:

jul 15, 2015 11:19:55 AM com.vaadin.server.VaadinServlet serveOnTheFlyCompiledScss
WARNING: Could not read persisted scss cache
java.lang.NullPointerException
at java.io.File.(Unknown Source)
at com.vaadin.server.VaadinServlet.loadPersistedScssCache(VaadinServlet.java:989)
at com.vaadin.server.VaadinServlet.serveOnTheFlyCompiledScss(VaadinServlet.java:957)
at com.vaadin.server.VaadinServlet.serveStaticResourcesInVAADIN(VaadinServlet.java:734)
at com.vaadin.server.VaadinServlet.serveStaticResources(VaadinServlet.java:704)
at com.vaadin.server.VaadinServlet.service(VaadinServlet.java:343)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:769)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:585)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:311)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:610)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:539)
at java.lang.Thread.run(Unknown Source)

jul 15, 2015 11:19:56 AM com.vaadin.server.VaadinServlet persistCacheEntry
WARNING: Could not persist scss cache because no real file was found for the compiled scss file. This might happen e.g. if serving the scss file directly from a .war file.

How can I make the scss compiler compile on the fly? What am I missing?

Hi,

The real solution is that you should do the theme compilation in compilation phase. I hate to say it, but providing this on the fly sass compilation is a architectural flaw in Vaadin, just causing problems and performance issue. I’m never using it. If I have a custom theme in my application, I’m compiling the theme by IDE tooling - during the development.

Add this to your vaadin-maven-plugin configuration:

<goal>compile-theme</goal> Then the actual css file is generated during the build. After that you can also finetune the build by exluding obsolete dependencies like vaadin-sass-compiler and also the .scss files from your jar/war file.

cheers,
matti

That worked, thank you very much!

That worked for me also. Thanks a lot!

Hi Enkara,

You said, “I’ve been able to include my theme as a resource.” If you don’t mind, kindly show me how you did that.

Thank you.

-Dan

Hi Enkara,

No need. I think I’ve got it. Thanks anyway.

-Dan

Hi Dan,

It might help somebody else if you’d share the solution. My guess is that you first didn’t pre-compile the theme into your theme jar file?

cheers,
matti

Hi Matti,

Following Mattis advice I added:

compile-theme

to my Maven plugin configuration and following Éric’s advice which I found here:

https://stackoverflow.com/questions/7120436/how-to-add-css-to-vaadin-maven-project

I put my theme here:

src/main/resources/VAADIN/themes/

-Dan

yep thanks, I have tried that location too with no luck