Maven项目的两种打包方式-spring-boot-mavne-plugin/maven-jar-plugin

Maven项目的两种打包方式-spring-boot-mavne-plugin/maven-jar-plugin

    • 1. 前言
      • Maven的两种打包方式
    • 2. 流程图
    • 3. spring-boor-maven-plugin打包
    • 4. maven-jar-plugin/maven-dependency-plugin打包

1. 前言

Maven的两种打包方式

  • spring-boot-maven-plugin
    springboot默认打包方式方便快捷,但是打出的jar包太大,一些公共的依赖每个jar都要有一份.
  • maven-jar-plugin/maven-dependency-plugin
    打包公共依赖和代码可以放开打包,不同jar包可以共用一个dependency.jar,使打包文件变小,需要额外引入打包依赖
    参考文档
    spring-boot-maven-plugin文档: spring-boot-maven-plugin
    maven-jar-plugin文档: maven-jar-plugin
    maven-dependency-plugin文档: maven-dependency-plugin

2. 流程图

Maven项目的两种打包方式-spring-boot-mavne-plugin/maven-jar-plugin_第1张图片

3. spring-boor-maven-plugin打包

pom.xlm增加

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-maven-pluginartifactId>
            
            <configuration>
                <skip>falseskip>
            configuration>
        plugin>
    plugins>
build>

4. maven-jar-plugin/maven-dependency-plugin打包

pom.xml增加

<build>
   <plugins>
    <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-jar-pluginartifactId>
        <configuration>
            <archive>
                <manifest>
                    <useUniqueVersions>trueuseUniqueVersions>
                    <addClasspath>trueaddClasspath>
                    <classpathPrefix>libclasspathPrefix>
                    
                    <mainClass>com.zlm.ApplicationmainClass>
                manifest>
            archive>
            <outputDirectory>../outputDirectoryoutputDirectory>
        configuration>
    plugin>
    <plugin>
        <groupId>org.apache.maven.pluginsgroupId>
        <artifactId>maven-dependency-pluginartifactId>
        <executions>
            <execution>
                <id>copy-dependenciesid>
                <phase>packagephase>
                <goals>
                    <goal>copy-dependenciesgoal>
                goals>
                <configuration>
                    <outputDirectory>../outputDirectory/liboutputDirectory>
                configuration>
            execution>
        executions>
    plugin>
plugins>

build>

你可能感兴趣的:(maven,jar,java)