【问题标题】:Spring Boot Maven Plugin and Grunt with live reload带有实时重载的 Spring Boot Maven 插件和 Grunt
【发布时间】:2016-08-18 22:05:55
【问题描述】:

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

我将整个 Web 前端结构移至 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 不会让我加载 angular&co)。

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

【问题讨论】:

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


    【解决方案1】:

    作为部分解决方案,我选择在端口 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 上正常工作,无需手动运行命令来服务它。

    【讨论】:

      猜你喜欢
      • 2017-09-12
      • 1970-01-01
      • 2016-01-25
      • 2014-06-20
      • 2017-03-26
      • 2017-08-24
      • 2015-02-04
      • 2019-07-12
      • 2018-01-07
      相关资源
      最近更新 更多