0

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)?

Manu
  • 4,019
  • 8
  • 50
  • 94

1 Answers1

0

As a partial solution, I opted for running a new server on port 9000 (default) to serve files every time I run my application.

Two things are necessary: (1) replace exec-maven-plugin part with this:

<plugin>
    <artifactId>exec-maven-plugin</artifactId>
    <groupId>org.codehaus.mojo</groupId>
    <version>1.4.0</version>
    <configuration>
          <executable>${basedir}/runGrunt.sh</executable>
    </configuration>
</plugin>

(2) Execute Maven goal exec:exec before running the application.

This way, the frontend is not available on port 8080, but it is correctly working on 9000 without the need to manually run the command to serve it.

Manu
  • 4,019
  • 8
  • 50
  • 94