Spring Boot Maven插件和Grunt实时重载

时间:2016-04-25 13:23:08

标签: angularjs maven spring-boot gruntjs spring-boot-maven-plugin

我创建了一个Spring Boot应用程序,我想部署一个通过Yeoman(角度生成器)生成的Web前端。但是,我无法开始工作:当我运行应用程序时,我的静态资源被部署用于生产(localhost:8080 / dist / index.html工作正常),而不是用于开发(localhost:8080 / app / index.html)工作不太酷。)

我将整个网络前端结构移动到static。通过终端,我可以cd到该文件夹​​(src/main/resources/static)并运行grunt buildgrunt serve;这样,当我在前端工作时,我可以利用实时重新加载。

然后,我在项目根目录中创建了以下脚本,以通过grunt构建我的前端:

echo 'Running grunt build...'
cd src/main/resources/static
grunt build
echo 'Done running grunt'

我修改了我的pom.xml,如下所示:

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

现在,当我执行mvn spring-boot:run时,我的Spring项目正确启动,但是grunt是为生产而构建的(访问app / index.html不会让我加载角度和协作)。

我如何连接东西,以便我可以执行mvn spring-boot:run并使我的前端项目编译,部署和实时重新加载(即我想访问localhost:8080 / app / index.html并获得角度&amp; co loaded)?

1 个答案:

答案 0 :(得分:0)

作为部分解决方案,我选择在端口9000(默认)上运行新服务器,以便在每次运行应用程序时提供文件。

有两件事是必要的:(1)用这个替换exec-maven-plugin部分:

<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)在运行应用程序之前执行Maven目标exec:exec。

这样,前端在端口8080上不可用,但它正在9000上正常工作,无需手动运行命令来提供服务。

相关问题