【发布时间】: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 build 和 grunt 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