【maven】lib与source分离打包

1.方式1 maven-jar-plugin

1.1 整体打包,包含所有lib

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <source>1.8</source>
        <target>1.8</target>
        <encoding>UTF-8</encoding>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <!-- 生成的jar中,不要包含pom.xml和pom.properties这两个文件 -->
            <addMavenDescriptor>true</addMavenDescriptor>
            <manifest>
                <!-- 是否要把第三方jar加入到类构建路径 -->
                <addClasspath>true</addClasspath>
                <!-- 外部依赖jar包的最终位置 -->
                <classpathPrefix>lib/</classpathPrefix>
                <!-- 项目启动类 -->
                <mainClass>com.maven.test.HisPCloudApplication</mainClass>
                <useUniqueVersions>false</useUniqueVersions>
            </manifest>
        </archive>
    </configuration>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-lib</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <outputDirectory>${project.build.directory}/lib</outputDirectory>
                <excludeTransitive>false</excludeTransitive>
                <stripVersion>false</stripVersion>
                <!--                            <includeScope>compile</includeScope>-->
                <includeScope>runtime</includeScope>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

直接进入目录下,jar -jar 启动即可

 1.2 局部打包 多个lib文件夹

追加如下配置

<execution>
    <id>copy-hislib</id>
    <phase>package</phase>
    <goals>
        <goal>copy-dependencies</goal>
    </goals>
    <configuration>
        <outputDirectory>${project.build.directory}/hislib</outputDirectory>
        <includeGroupIds>com.maven.test</includeGroupIds>
        <excludeTransitive>false</excludeTransitive>
        <stripVersion>false</stripVersion>
        <includeScope>compile</includeScope>
        <includeScope>runtime</includeScope>
        <overWriteReleases>false</overWriteReleases>
        <overWriteSnapshots>false</overWriteSnapshots>
        <overWriteIfNewer>true</overWriteIfNewer>
    </configuration>
</execution>

如图效果

 加载方式

1.MANIFEST.MF中会有打包后的lib路径,所以需要修改pom,参考如下

 2.MANIFEST.MF效果如下

2.或使用启动命令加载

-Djava.ext.dirs=hislib;$JAVA_HOME/jre/lib/ext

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值