maven打包(lib,config,bin分离)

添加plugn

   <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-jar-plugin</artifactId>
               <configuration>
                   <classesDirectory>target/classes/</classesDirectory>
                   <archive>
                       <!--生成的jar中,不要包含pom.xml和pom.properties这两个文件-->
                       <addMavenDescriptor>false</addMavenDescriptor>
                       <manifest>
                           <mainClass>com.cyy.MvnPackageApplication</mainClass>
                           <!-- 打包时 MANIFEST.MF文件不记录的时间戳版本 -->
                           <useUniqueVersions>false</useUniqueVersions>
                           <addClasspath>true</addClasspath>
                           <classpathPrefix>lib/</classpathPrefix>
                       </manifest>
                       <manifestEntries>
                           <!--jar中的MANIFEST.MF文件ClassPath需要添加config目录才能读取到配置文件-->
                           <Class-Path>config/.</Class-Path>
                       </manifestEntries>
                   </archive>
                   <excludes>
                       <exclude>**/*.yml</exclude>
                       <exclude>**/*.properties</exclude>
                       <exclude>**/*.sh</exclude>
                       <exclude>**/*.bat</exclude>
                   </excludes>
               </configuration>
           </plugin>
           <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-assembly-plugin</artifactId>
               <version>2.4</version>
               <configuration>
                   <descriptors>
                       <descriptor>src/main/assembly/assembly.xml</descriptor>
                   </descriptors>
                    <archive>
                        <manifest>
                            <mainClass>com.cyy.MvnPackageApplication</mainClass>
                        </manifest>
                    </archive>
               </configuration>
               <executions>
                   <execution>
                       <id>make-assembly</id>
                       <phase>package</phase>
                       <goals>
                           <goal>single</goal>
                       </goals>
                       <configuration>
                           <finalName>${project.artifactId}</finalName>
                           <descriptors>
                               <descriptor>src/main/assembly/assembly.xml</descriptor>
                           </descriptors>
                           <outputDirectory>./dist/</outputDirectory>
                       </configuration>
                   </execution>
               </executions>
           </plugin>

src/main/assembly下添加如下文件

<assembly>
    <id>bin</id>
    <formats>
        <format>zip</format>
    </formats>
    <dependencySets>

        <!--依赖包打包到lib下,false lib下不包含本工程包, true:包含-->
        <dependencySet>
            <useProjectArtifact>false</useProjectArtifact>
            <outputDirectory>lib</outputDirectory>
        </dependencySet>
    </dependencySets>

    <fileSets>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <includes>
                <include>README.txt</include>
            </includes>
        </fileSet>

        <!-- 打包启停脚本到bin下 -->
        <fileSet>
            <directory>src/main/resources/sh</directory>
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>*.sh</include>
                <include>*.bat</include>
            </includes>
        </fileSet>

        <!-- 打包配置文件到config下 -->
        <fileSet>
            <directory>src/main/resources</directory>
            <outputDirectory>/config</outputDirectory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.yml</include>
                <include>**/*.xml</include>
            </includes>
        </fileSet>

        <!-- 打包本工程jar文件到根目录下 -->
        <fileSet>
            <directory>target</directory>
            <includes>
                <include>*.jar</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>

    </fileSets>
</assembly>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值