首页 > 其他分享 >frontend-maven-plugin +jib-maven-plugin 构建前后端混合docker 项目

frontend-maven-plugin +jib-maven-plugin 构建前后端混合docker 项目

时间:2022-09-28 21:33:53浏览次数:92  
标签:jib plugin maven frontend com resources

核心是基于frontend-maven-plugin+ jib-maven-plugin 构建基于docker 运行的项目

项目结构

├── README.md
├── frontends  // web 
│   ├── app.css
│   ├── index.html
│   ├── package.json
│   └── yarn.lock
├── pom.xml // 构建
└── src
    ├── main // backend 
    │   ├── java
    │   │   └── com
    │   │       └── dalong
    │   │           └── Main.java
    │   └── resources
    └── test
        └── java

代码说明

主要说明项目运行的,具体代码参考github

  • pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>com.dalong</groupId>
    <artifactId>guiceappdemo</artifactId>
    <version>1.0-SNAPSHOT</version>
 
    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
 
    <dependencies>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>5.1.0</version>
        </dependency>
        <dependency>
            <groupId>com.sparkjava</groupId>
            <artifactId>spark-core</artifactId>
            <version>2.9.4</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.11.3</version>
                <configuration>
                    <workingDirectory>frontends</workingDirectory> // 指定frontends 插件工作目录
                </configuration>
                <executions>
                    <execution>
                        <!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
                        <id>install node and yarn</id>
                        <goals>
                            <goal>install-node-and-yarn</goal>
                        </goals>
                        <!-- optional: default phase is "generate-resources" -->
                        <phase>generate-resources</phase>
                        <configuration>
                            <nodeVersion>v16.8.0</nodeVersion>
                            <yarnVersion>v1.22.11</yarnVersion>
                        </configuration>
                    </execution>
                    <execution>
                        <id>yarn install</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>install</arguments>
                        </configuration>
                    </execution>
                    <execution>
                        <id>build minimized webpack bundle</id>
                        <phase>generate-resources</phase>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <configuration>
                            <arguments>b-publish</arguments>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
               // jib-maven 构建进行,不需要docker 引擎
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>jib-maven-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <to>
                        <image>dalongrong/mydemofrontendapp</image> // 实际需要定义为自己的
                    </to>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>build</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
 
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>Copy  target static folder</id>
                        <phase>process-resources</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                          // resource 资源拷贝
                            <outputDirectory>${project.build.outputDirectory}/public</outputDirectory> // public 做为web 的首页,基于sparkjava 框架
                            <resources>
                                <resource> 
                                    <directory>frontends/dist</directory>
                                    <filtering>false</filtering>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
  • 构建&&运行

会启动构建以及push 容器镜像

  • 构建
mvn clean package 
  • 运行
docker run -it -p 8080:8080  dalongrong/mydemofrontendapp
  • 效果

 

 

说明

以上是基于frontend-maven-plugin +jib-maven-plugin 构建以及运行一个前后端混合的项目,实现前后端一体,同时实现无容器引擎的运行
## 参考资料
https://github.com/GoogleContainerTools/jib/tree/master/jib-maven-plugin
https://parceljs.org/
https://github.com/eirslett/frontend-maven-plugin
https://github.com/rongfengliang/maven-frontend-maven-jib

标签:jib,plugin,maven,frontend,com,resources
From: https://www.cnblogs.com/rongfengliang/p/16739654.html

相关文章

  • maven 加载依赖sqljdbc4报错
    错误现象:MavenFailuretofindcom.microsoft.sqlserver:sqljdbc4:jar:4.0解决方法:1.下载对应的sqljdbc4.jar包2.shell窗口执行命令mvninstall:install-file-D......
  • idea使用maven ------- 程序包不存在
    排查步骤1、检查ideamaven配置 -》》maven配置正常2、检查依赖是否引入-》》依赖已经引入3、本地仓库查看jar包是否导入 -》》》已经导入 解决 ......
  • Maven-私服搭建与配置
    一、maven私服搭建1.下载地址https://help.sonatype.com/repomanager3/product-information/download/download-archives---repository-manager-32.启用tar-zxvfnexu......
  • 创建springboot+maven项目
    参考:https://www.cnblogs.com/ygfsy/p/13675122.html 目录结构-->在项目下创建一个Control包,用于返回给前端的接口   测试接口是否通 ......
  • maven 拉取的 jar 包 功能逻辑 与 实际逻辑不同
    20220921sdk服务有一段根据url是否带参数的判断的实际代码:maven加载jar包后,运行都有报错,查看源码:直接省略了对url的判断,导致url没有加参数的场景都会抛数组......
  • 安全同学讲Maven间接依赖场景的仲裁机制
    简介: 去年的Log4j-core的安全问题,再次把供应链安全推向了高潮。在供应链安全的场景,蚂蚁集团在静态代码扫描平台-STC和资产威胁透视平台-哈勃这2款产品在联合合作下,优势互......
  • wagon-maven-plugin实现自动打包部署到服务器
    https://dandelioncloud.cn/article/details/14893795494766714901.在maven中添加依赖<dependency><groupId>org.codehaus.mojo</groupId......
  • docker集成分词器时报Caused by: java.nio.file.FileSystemException: /usr/share/ela
    官网https://github.com/medcl/elasticsearch-analysis-ik/releases/tag/v6.8.6下载好的zip包cp到/usr/share/elasticsearch/plugins/下后解压它会带有一个config包,或者......
  • 1.SSM框架 maven模块+oracle+注解开发
    一、SSM框架maven模块+oracle+注解开发1.初始化数据库--创建表空间语句createtablespacessm_69datafile'c:\ssm_69.dbf'size100mautoextendonnext10m;--创建用......
  • P4 MAVEN的目录结构
    #4MAVEN的目录结构和手动创建MAVEN项目##4.1MAVEN的目录结构   5MAVEN项目的编译和启动5.1准备工作第一次会下载很多包,要改变一下下载路径会下载很多......