背景:

项目需要在代码里面嵌入海康威视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>

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

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐