zoukankan      html  css  js  c++  java
  • maven打包插件maven-assembly-plugin

    1.POM文件添加jar包生成插件

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <version>3.0.2</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <mainClass>${mainClass}</mainClass>
                                <!-- 是否指定项目classpath下的依赖 -->
                                <addClasspath>true</addClasspath>
                                <!-- 指定依赖的时候声明前缀 -->
                                <classpathPrefix>./lib/</classpathPrefix>
                                <!--依赖是否使用带有时间戳的唯一版本号,如:xxx-1.3.0-20121225.012733.jar-->
                                <useUniqueVersions>false</useUniqueVersions>
                            </manifest>
                        </archive>
                    </configuration>
                </plugin>
    

    2.添加第三方依赖打包插件

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                       <execution>
                         <id>copy</id>
                         <phase>package</phase>
                         <goals>
                            <goal>copy-dependencies</goal>
                         </goals>
                         <configuration>
                            <outputDirectory>${project.basedir}/target/lib</outputDirectory>
                         </configuration>
                        </execution>
                    </executions>
                </plugin>
    

    3.添加assembly打包插件

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <executions>
                        <!-- 配置执行器 -->
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase><!-- 绑定到package生命周期阶段上 -->
                            <goals>
                                <goal>single</goal><!-- 只运行一次 -->
                            </goals>
                            <configuration>
                                <finalName>${project.name}</finalName>
                                <!--配置描述文件路径-->
                                <descriptor>assembly.xml</descriptor>
                            </configuration>
                        </execution>
                     </executions>
                </plugin>   
    

    4.添加打包描述文件assembly.xml

    <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
        <id>dropwizard-package</id>
        <!--打包格式-->
        <formats>
            <format>tar.gz</format>
        </formats>
        <includeBaseDirectory>false</includeBaseDirectory>
        <fileSets>
            <!--导入指定文件到tar.gz包-->
            <fileSet>
                <directory>${project.basedir}/target</directory>
                <outputDirectory>./${project.name}</outputDirectory>
                <directoryMode>0775</directoryMode>
                <fileMode>0775</fileMode>
                <includes>
                    <include>*.jar</include>
                </includes>
            </fileSet>
            <fileSet>
                <directory>${project.basedir}/target/lib</directory>
                <outputDirectory>./${project.name}/lib</outputDirectory>
                <directoryMode>0775</directoryMode>
                <fileMode>0775</fileMode>
            </fileSet>
            <fileSet>
                <directory>${project.basedir}/src/main/resources</directory>
                <outputDirectory>./${project.name}/conf</outputDirectory>
                <directoryMode>0775</directoryMode>
                <fileMode>0775</fileMode>
            </fileSet>
        </fileSets>
    </assembly>   
    

    5.Over!!!

  • 相关阅读:
    PowerToys插件扩展(类似Alfred)
    .net打独立运行环境遇到无法trim遇到的bug
    blazor wasm开发chrome插件
    将php代码部署到新浪云测试(简单方法,包含数据库的连接)
    python修改csv某一列的内容
    windows10调用libcurl
    Java动态脚本Groovy,高级啊!
    Linux 配置Git
    Java动态脚本Groovy读取配置文件
    Java动态脚本Groovy获取Bean(奇淫技巧操作)
  • 原文地址:https://www.cnblogs.com/ilovena/p/9973813.html
Copyright © 2011-2022 走看看