• maven项目部署打包


    方法一、把maven依赖的jar包一起打包

    http://maven.apache.org/plugins/maven-assembly-plugin/usage.html

    pom/build中加入以下plugin。

    注意修改mainClass

          <build>
            <defaultGoal>compile</defaultGoal>
                   <plugins>  
                <plugin>  
                    <artifactId>maven-assembly-plugin</artifactId>  
                    <configuration>  
                        <archive>  
                            <manifest>  
                                <mainClass>com.lyp.provider.DemoProvider</mainClass>  
                            </manifest>  
                        </archive>  
                        <descriptorRefs>  
                            <descriptorRef>jar-with-dependencies</descriptorRef>  
                        </descriptorRefs>  
                    </configuration>  
                </plugin>  
            </plugins>  
        </build>

    执行mvn assembly:assembly

    方法二、复制jar包到target/lib

        <!-- 打包jar文件时,配置manifest文件,加入lib包的jar依赖 -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-jar-plugin</artifactId>
                    <configuration>
                        <classesDirectory>target/classes/</classesDirectory>
                        <archive>
                            <manifest>
                                <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                                <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                                <useUniqueVersions>false</useUniqueVersions>
                                <addClasspath>true</addClasspath>
                                <classpathPrefix>lib/</classpathPrefix>
                            </manifest>
                            <manifestEntries>
                                <Class-Path>.</Class-Path>
                            </manifestEntries>
                        </archive>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-dependency-plugin</artifactId>
                    <executions>
                        <execution>
                            <id>copy-dependencies</id>
                            <phase>package</phase>
                            <goals>
                                <goal>copy-dependencies</goal>
                            </goals>
                            <configuration>
                                <type>jar</type>
                                <includeTypes>jar</includeTypes>
                                <useUniqueVersions>false</useUniqueVersions>
                                <outputDirectory>
                                    ${project.build.directory}/lib
                                </outputDirectory>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>

     执行maven install,安装私有库同时,可以copy jar包到target/lib

  • 相关阅读:
    Hugo搭建的博客删除文章事宜
    [GIT] Git学习笔记
    VS Code: 解决安装code-runner扩展run后无法在只读编辑器下编辑
    c/c++结构体总结
    恢复U盘做启动盘后的容量
    Manjaro安装Mysql
    win10环境下安装manjaro kde(双系统)
    IDEA设置编辑区主题
    IDEA设置主体、窗体及菜单的字体大小
    IDEA设置项目文件编码
  • 原文地址:https://www.cnblogs.com/tenghoo/p/maven_assembly.html
Copyright © 2020-2023  润新知