unsure whether this is a question too basic (apologize if so): Being into moving a modestly large Vaading (war-packed) application to Spring Boot, I am amazed to see things move along pretty smoothly, but I so far didn’t manage to get our static items, such as icons and stylesheets (which, in the .war world, live in src/main/webapp/VAADIN/themes) into the Spring Boot application. Can anyone enlighten me how Spring Boot needs to be configured / where these files need to be placed in order to actually have them accessible at runtime?
Vaadin will find those from classpath as well, so adding that stuff to src/main/resources/VAADIN/… should do fine. Spring boot also has this “static” directory, but it might be hard to reference that stuff past Vaadin servlet. Works if you map vaadin servlet to a different location.
I also have a Vaadin Spring boot application (generating a jar file), however when I try to read a static file using:
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
new File(basepath + "/navigation.xml");
I get the following error during runtime, which is correct, because the file is in /src/main/resources and not in webapp.:
C:\Projects\xxx\src\main\webapp\navigation.xml (System cannot find the file)
Starting the application from Eclipse via
vaadin:compile spring-boot:run
Where is the configuration coming from that vaadin tries to search in the webapp folder?
Any hint would be appreciated.
pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<vaadin.version>7.6.5</vaadin.version>
<vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url>
</repository>
</repositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<version>${vaadin.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-spring-boot-starter</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.vaadin.addon</groupId>
<artifactId>v-ol3</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>org.vaadin</groupId>
<artifactId>viritin</artifactId>
<version>1.50</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiled</artifactId>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<!-- For widgetset compilation, vaadin-client-compiler is automatically
added on the compilation classpath by vaadin-maven-plugin so normally there
is no need for an explicit dependency. <dependency> <groupId>com.vaadin</groupId>
<artifactId>vaadin-client-compiler</artifactId> </dependency> -->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.plugin.version}</version>
<configuration>
<extraJvmArgs>-Xmx512M -Xss1024k</extraJvmArgs>
<!-- We are doing "inplace" but into subdir VAADIN/widgetsets. This
way compatible with Vaadin eclipse plugin. -->
<webappDirectory>${basedir}/src/main/resources/VAADIN/widgetsets
</webappDirectory>
<hostedWebapp>${basedir}/src/main/resources/VAADIN/widgetsets
</hostedWebapp>
<draftCompile>false</draftCompile>
<compileReport>false</compileReport>
<style>OBF</style>
<strict>true</strict>
<persistentunitcachedir>${basedir}/target/gwt-unitCache</persistentunitcachedir>
<deploy>${basedir}/target/gwtdirt</deploy>
<module>AppWidgetset</module>
</configuration>
<executions>
<execution>
<goals>
<!--<goal>update-theme</goal> -->
<goal>update-widgetset</goal>
<goal>compile</goal>
<!-- disabled by default to use on-the-fly theme compilation -->
<!-- <goal>compile-theme</goal> -->
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Posted this post also to https://vaadin.com/forum#!/thread/9721905 which was the other post I found when investigating the issue of Vaadin with Spring Boot and custom themes.
Am posting this in case it helps anyone. Had a real problem with getting Vaadin custom themes to work with Spring Boot with a Jar deployment. The application worked fine in development in Intellij but when deployed to AWS no themes. The src/main/webapp folder wasn’t making it to the deployment Jar. I tried putting the webapp/VAADIN and just the VAADIN folder in /src/main/resources/, as per Spring Boot docs but that didn’t work either. Vaadin wasn’t finding the themes.
After a lot of experimenting with various Maven plugins, the following is currently working well. In the pom.xml, in the section (where you also define for spring-boot-maven-plugin and vaadin-maven-plugin), just add:
<resources>
<resource>
<directory>src/main/webapp</directory>
</resource>
</resources>
One concern is that the Spring Boot docs (http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-spring-mvc-static-content) explicitly tell you “Do not use the src/main/webapp directory if your application will be packaged as a jar. Although this directory is a common standard, it will only work with war packaging and it will be silently ignored by most build tools if you generate a jar.” I am hoping there are no negative consequences if you force src/main/webapp to be included.
The Vaadin docs say that “Custom themes are placed under the VAADIN/themes/ folder of the web application (under WebContent in Eclipse or src/main/webapp in Maven projects). This location is fixed” Perhaps Vaadin should allow a bit more flexibility for custom themes to be placed in the resources directory.
Give Vaadin 7.7 a try, it vastly improves Spring Boot integration. Themes in src/main/resources are now supported, among other things. Theme compilation also works without further configuration.