I created a Spring Boot application and I want to deploy a web front-end generated via Yeoman (angular generator). However, I cannot get things to work: when I run the application, my static resources are deployed for production (localhost:8080/dist/index.html is working cool), not for development (localhost:8080/app/index.html is not working cool).
I moved the entire web front end structure into static
. Via terminal, I can cd to that folder (src/main/resources/static
) and run grunt build
and grunt serve
; this way, when I work on the frontend, I can leverage live reload.
Then, I created the following script in the project root to build my front end via grunt:
echo 'Running grunt build...'
cd src/main/resources/static
grunt build
echo 'Done running grunt'
I modified my pom.xml
as follow:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>Grunt build</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${basedir}/runGrunt.sh</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Now, when I execute mvn spring-boot:run
, my Spring projects starts correctly, but grunt is built for production (accessing app/index.html does not let me load angular&co).
How can I wire things so that I can execute mvn spring-boot:run
and get my front end project compiled, deployed and with live reload (i.e. I want to access localhost:8080/app/index.html and get angular&co loaded)?