Spring Boot jar packaging Vaadin theme
Problem here is, that vaadin custom theme is not served as “static” with plain tomcat but thought the vaadinservlet loaded from classpath resource url, unfotunately jar protocol is not enabled in vaadin spring servlet to serve resources in suitable paths.
this worked for me in vaadin 7.7.7± vaadin-spring-boot-starter 1.0.0 - 1.2.0
-
Put your theme into src/main/resources/META-INF/resources/VAADIN/themes/…
-
Override default spring vaadin servlet to allow to load resources from that path when packed to “jar” this class in your component scan package will do the trick:
[code]
@SpringComponent(“vaadinServlet”)
public class MetaSpringVaadinServlet extends SpringVaadinServlet {
private static final Logger logger = Logger.getLogger(MetaSpringVaadinServlet.class);
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
logger
.info(“Replacing default VaadinSpringServlet with custom to allow JAR protocol in /META-INF/resources/VAADIN/”);
}
@Override
protected boolean isAllowedVAADINResourceUrl(HttpServletRequest request, URL resourceUrl) {
if (“jar”.equals(resourceUrl.getProtocol())) {
if (!resourceUrl.getPath().contains(“!/VAADIN/”)
&& !resourceUrl.getPath().contains(“!/META-INF/resources/VAADIN/”)) {
logger.warn(“Blocked attempt to access a JAR entry not starting with /VAADIN/ or /META-INF/resources/VAADIN/: "
+ resourceUrl);
return false;
}
logger.debug(“Accepted access to a JAR entry using a class loader: " + resourceUrl);
return true;
} else {
if (!resourceUrl.getPath().contains(”/VAADIN/”) || resourceUrl.getPath().contains(“/…/”)) {
logger.warn("Blocked attempt to access file: " + resourceUrl);
return false;
}
logger.debug("Accepted access to a file using a class loader: " + resourceUrl);
return true;
}
}
}
[/code]Check source of SpringVaadinServlet to reference and let me know. This is only way i was able to serve both Spring MVC Templates and Vaadin custom theme resources in spring boot “executable” jar with embeded tomcat server.
you can put your *.JSP files into src/main/resources/META-INF/resources/WEB-INF/jsp if you are using Spring MVC alongside with Vaadin from JAR file
application.properties
#Internal view resolver
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
pom.xml deps
[code]
org.apache.tomcat.embed
tomcat-embed-jasper
provided
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
[/code]I was not using “fat” jar but ordinary jar without dependencies included (it has different structure)
e.g… pom.xml
<build>
<plugins>
<!-- copy dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
then test with
java -cp target/lib/:targer/myapp.jar myapp.Launcher
sorry for my english, hope i can help
edit: for vaadin spring 2.0 and vaadin 8.0.0 you just put them into src/main/resources/VAADIN/themes/… and it should work thanks to this insightfull commit:
https://github.com/vaadin/spring/commit/49efce25c2af8ddf9039e46211182cab0deb78d7