使用 maven 在 React 应用程序中打包 Spring Boot 应用程序 [英] Package Spring Boot application inside a React app with maven

查看:97
本文介绍了使用 maven 在 React 应用程序中打包 Spring Boot 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可用的 React 应用程序,我想向其中添加一个 Spring Boot 应用程序.我的最终目标是在运行 mvn clean package 后拥有一个包含 React 应用程序和 Spring Boot 应用程序的单一 war 文件.

I have a working React app, and I would like to add a Spring Boot application to it. My final goal is to have a single war file with the React app and the Spring Boot application after running mvn clean package.

现在,如果我运行 mvn clean package,它将编译 React 应用程序并将其成功打包到一个 war 文件中.到现在为止还挺好.但是我不知道如何使用相同的命令编译 Spring Boot 应用程序并将其添加到包中.

Now, if I run mvn clean package it will compile the React app and package it into a war file successfully. So far so good. But I have no idea how to compile and add a Spring Boot application to the package with the same command.

我找到了一个类似的解决方案:https://github.com/kantega/react-and-弹簧

I found a similar solution: https://github.com/kantega/react-and-spring

但这对我不起作用.我需要将 React 应用程序作为主项目,并且需要通过 maven 命令编译它.

BUT this is not working for me. I need the React app to be the main project, and I need it to be compiled by a maven command.

当我调用 mvn clean package 时,我使用 exec-maven-plugin 告诉编译器使用 yarn.我试图向这个插件添加另一个目标,它符合后端部分,但结果是一个无限循环.

I use the exec-maven-plugin to tell the compiler to use yarn when I call mvn clean package. I tried to add an other goal to this plugin which complies the backend part but the result was an infinite loop.

流程应该是这样的:

  1. 编译后端

  1. compile backend

编译前端

将它们打包成一个单一的war文件

package it together in a single war file

您有什么建议吗?

推荐答案

感谢@Lorelorelore 的评论,我能够创建一个解决方案.

Thanks for @Lorelorelore's comment, I was able to create a solution.

使用 JHipster,您可以像我在问题中描述的那样创建一个应用程序,但是充满了不必要的生成代码.我删除了所有不相关的代码,并添加了一些重要的部分,结果是一个更干净、更小的应用程序.

With JHipster you can create an application like I described in the question, BUT with full of unnecessarily generated code. I removed all the irrelevant code, and added some important part, and the result was a cleaner, smaller application.

所以我创建了一个更简单的样板代码.

这里是 GitHub 链接: https://github.com/archangel1991/react-with-spring

我希望它会有所帮助:)

I hope it will help :)

这篇关于使用 maven 在 React 应用程序中打包 Spring Boot 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆