maven打包插件

一, maven-assembly-plugin

Assembly 插件支持将项目的所有依赖、文件都打包到同一个输出文件中。目前支持输出以下文件类型:

  • zip
  • tar
  • tar.gz (or tgz)
  • tar.bz2 (or tbz2)
  • tar.snappy
  • tar.xz (or txz)
  • jar
  • dir
  • war

 

二, maven-jar-plugin

将java代码打成jar包, 并指定执行程序入口置主类MainClass

<plugin>  
        <groupId>org.apache.maven.plugins</groupId>  
        <artifactId>maven-jar-plugin</artifactId>  
        <configuration>  
          <archive>  
            <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile>  
          </archive>  
        </configuration>  
      </plugin>

 

 

三, maven-dependency-plugin

将 resources/lib 目录所有 Jar 包一并拷贝到输出目录的 lib 目录下

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                         <!--将 resources/lib 目录所有 Jar 包一并拷贝到输出目录的 lib 目录下-->
                        <outputDirectory>
                            ${project.build.directory}/lib
                        </outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>

将所有jar包打成一个最终的jar

<plugin>  
            <groupId>org.apache.maven.plugins</groupId>  
            <artifactId>maven-assembly-plugin</artifactId>  
            <version>2.5.5</version>  
            <configuration>  
                <archive>  
                    <manifest>  
                        <mainClass>com.xxg.Main</mainClass>  
                    </manifest>  
                </archive>  
                <descriptorRefs>  
                    <descriptorRef>jar-with-dependencies</descriptorRef>  
                </descriptorRefs>  
            </configuration>  
            <executions>  
                <execution>  
                    <id>make-assembly</id>  
                    <phase>package</phase>  
                    <goals>  
                        <goal>single</goal>  
                    </goals>  
                </execution>  
            </executions>  
</plugin>

 

 

posted @ 2023-04-01 22:22  車輪の唄  阅读(82)  评论(0编辑  收藏  举报  来源