idea本地jar,使用maven打包本地依赖,实现自动编译到项目里

背景:

项目需要在代码里面嵌入海康威视sdk的jar,做第二次开发。获取摄像头的历史视频等数据,由于海康的jar文件是自己开发和编译,没有在仓库里面下载,需要复制海康Jar包和其他编译文件,如:jna.jar,excamples.jar导入到项目里面,位置如下图:

执行 mvn 指令界面

办法一

1. 安装jna. jar 到 Maven 仓库

首先,如果你的本地 jar 不在 Maven 中央仓库中,你需要将它安装到你的本地 Maven 仓库中。使用下面的命令:

mvn install:install-file 
    -Dfile=F:\xxx\bigdata\2024\vision\lib\jna.jar //jna.jar文件的位置 
    -DgroupId=com.xxx.jna 
    -DartifactId=com-xxx-jna 
    -Dversion=1.0.0 //版本号,可以自己根据实际情况填写
    -Dpackaging=jar

2. 安装examples.jar到 Maven 仓库,规则如步骤1

mvn install:install-file 
    -Dfile=F:\xxx\bigdata\2024\vision\lib\examples.jar 
    -DgroupId=com.xxx.examples 
    -DartifactId=com-xxx-examples
    -Dversion=1.0.0 
    -Dpackaging=jar

 3. 找到引用jna.jar,examples.jar的pom.xml文件,添加如下依赖,然后重新编译

 

<dependency>
            <groupId>com.xxx.jna</groupId> <!-- 名字可以自己定义 要唯一-->
            <artifactId>com-xxx-jna</artifactId> <!--自己定义 -->
            <version>1.0.0</version> <!--版本号,根据实际情况配置-->
        </dependency>
        <dependency>
            <groupId>com.xx.examples</groupId>
            <artifactId>com-xx-examples</artifactId>
            <version>1.0.0</version>
        </dependency>

注意:确保打包包含所有依赖

确保你的 pom.xml 文件中有适当的插件配置的如:

<build>
        <finalName>${project.artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

办法二

1.在办法一里面,第3步的基础上

<dependency>
            <groupId>com.xx.jna</groupId> <!-- 名字可以自己定义 要唯一-->
            <artifactId>com-xx-jna</artifactId><!--自己定义 -->
            <version>1.0.0</version><!--版本号,根据实际情况配置-->
            <systemPath>${project.basedir}/../../lib/jna.jar</systemPath><!--加上此标签,引用绝对路径jar,不需要每次新建环境,专门配置maven-->
            <scope>system</scope>
</dependency>
<dependency>
           <groupId>com.xx.examples</groupId>
            <artifactId>com-xx-examples</artifactId>
            <version>1.0.0</version>
            <systemPath>${project.basedir}/../../lib/examples.jar</systemPath>
            <scope>system</scope>
</dependency>

2.pom.xml文件里面,找到spring-boot-maven-plugin位置,增加标签<includeSystemScope>

<plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                    <version>${spring-boot.version}</version>
                    <configuration>
                        <includeSystemScope>true</includeSystemScope><!-- true :表示打包的时候,会自动把本地jar包,打包项目里面一-->
                    </configuration>
                    <executions>
                        <execution>
                            <goals>
                                <goal>repackage</goal>
                            </goals>
                        </execution>
                    </executions>
</plugin>

觉得写的不错的朋友,请点点赞!❤❤❤❤❤❤❤❤ 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿方

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值