java - Spring Boot - 在 docker 容器内构建 maven 项目(JAR 文件)
问题描述
我有一个运行具有以下文件夹结构的 VueJS 应用程序的 Spring Boot 项目:
root
+-- client
| +-- [vue app]
| +-- pom.xml
+-- server
| +-- [spring boot app]
| +-- pom.xml
+-- pom.xml
在构建应用程序时,client
我正在运行以下命令。pom.xml
该脚本正在安装npm
并运行npm run build
以创建dist/
要在下一个代码片段中复制的文件夹。
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<executions>
<!-- Install our node and npm version to run npm/node scripts-->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v11.5.0</nodeVersion>
</configuration>
</execution>
<!-- Install all project dependencies -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<!-- Optional configuration which provides for running any npm command -->
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- Build and minify static files -->
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
在目录中的pom.xml
-file 中,server
我有以下配置将资源从类复制client/dist/
到类路径的静态资产server
:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<!-- Copy Vue files to src-folder in server -->
<id>copy Vue.js frontend content</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>src/main/resources/public</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>${project.parent.basedir}/client/dist</directory>
<includes>
<!-- Make sure assets are added to static/ folder in vue.config.js-->
<include>static/</include>
<include>index.html</include>
<include>favicon/</include>>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
最终目标是让应用程序通过 jenkins 管道构建到 docker 容器中。
但是,我的问题是,由于生产设置,我无法通过 maven 下载或安装 node / npm(由于安全原因,所有外部包都被阻止)。
因此,我需要一种构建 vue 应用程序的方法,并在创建.jar
文件时将文件复制到类路径,而无需通过 maven 实际执行此操作。
一个想法是使用node
已安装的 docker 映像并通过 docker 映像进行构建。但是,我对此的实际方法一无所知。如果有人有一个想法,将不胜感激。
解决方案
推荐阅读
- python - 使用 1 到 100 的不同输入重复一个 python 脚本
- javascript - reactJS:从“yyyy-mm-ddThh-mm-ss.sssZ”转换为“yyyy-mm-dd hh-mm”
- opengl - 如何访问底层 Skia 上下文并运行我自己的 opengl 命令进行绘制?
- php - 在现有的 Laravel 项目上安装 laravel/sail 时如何选择多个服务?
- twig - 如何使用 Twig 检查 Shopware 6 中的当前活动类别?
- python - 用于实现自组织地图的库 sompy
- ios - iOS 应用程序加载器卡在识别控件上
- r - 标题到数据框
- typescript - 如何在 Typescript 中定义具有一些可选指定属性以及一些必需指定属性的类型
- javascript - 以 JSON 格式存储 URL 的 CSS 数组