This is a Maven project demonstrating how to insert the static assets from a separate project retrievable via bower into a Spring Boot runnable jar.
Read more about the motivations at http://nblair.github.io/2016/04/21/combining-spring-boot-bower/.
- Maven
The build process uses node, npm and bower, however it's not required that you have them installed locally; the frontend-maven-plugin will install them in a generated directory under the project for you.
mvn package
The clean
goal is configured to delete the bower_components
and node_modules
folders, but not the node
folder.
- maven-dependency-plugin fires first, downloading the Spring Boot jar from our Artifact Repository. It then unpacks the jar to the specified
<outputDirectory>
(best to nest this under${project.build.directory}
). - frontend-maven-plugin fires next. If it hasn't downloaded node for your system, it will (under
${basedir}/node/
). Then it will runnpm install
(really just to get bower), then it will runbower install
.bower.json
declares a dependency on our front end project, and now we have a copy sitting in${project.build.directory}
next to the back-end project. - Then, during the
prepare-package
phase, the maven-resources-plugin has 3 executions:- Copy the bower_components (which was generated by the
bower install
in step 2) folder from the front-end site into META-INF/resources/bower_components in the outputDirectory of step 1. - Copy the rest of the assets of the front end project site (excluding bower_components) into into META-INF/resources in the outputDirectory of step 1.
- Copy any beta specific configuration into the project (root of the classpath).
- Copy the bower_components (which was generated by the
- Now sitting on the filesystem is an exploded Spring Boot jar with our assets from the front end site piled into it. The last plugin to fire is the maven-jar-plugin, with a few bits of custom configuration:
classesDirectory
is set to be the root of our exploded Spring Boot jar.- A manifestFile - the original from the Spring Boot jar - is explicitly declared. If we don't do this, the maven-jar-plugin will create one on it's own that's missing the properties Spring Boot expects.
- The
compress
flag MUST be false. Spring Boot jars contain jars (inside the lib directory), Spring Boot won't start properly if these jars get compressed.