GKLBB

当你经历了暴风雨,你也就成为了暴风雨

导航

常见问题解决 --- 海康OpenAPI安全认证库的demo运行报错

我要开发一个对接海康isc平台的oss的api,发现需要有海康登录库和ak、sk的配合才能完成。

在海康官方下载OpenAPI安全认证库(JAVA) V1.1.11,解压后用idea打开demo发现一对报错。

解决办法:

1.修复基本的错误。比如包名报错,应该是  package ga; 

2.修复maven依赖导入报错。首先是artemis-http-client这个依赖是海康自研的依赖包,pom中配置的源是海康内部的仓库,我们无权访问,你可以打开链接看看会提示502报错。在maven中央仓库中搜索可以发现有这个包,但是是1.1.3的旧版本,我导入旧版本会提示代码报错,因为代码有兼容性问题,必须用新版。在这里我插一句话基础常识,maven仓库有很多,最大的仓库叫做 maven中央仓库,里面放置有上万个jar包。还有其他官方提供的自己的仓库,比如spring官方自己搭建了一个maven仓库里面都是最新的spring jar包,也就是说,中央的最全但是不新,自有的最新但是不全。 这里在idea导入自己下载的jar包我知道的有三种方法,

第一种,在项目下创建一个lib文件夹,里面放置所有你要导入的库,在库上右键 作为库导入

第二种,在设置里的项目结构---模块---依赖中添加你要的库

第三种,就是离线安装到maven本地仓库中,我建议使用这种方式方便我们后期编译jar。 


要将这三个 JAR 包手动安装到本地 Maven 仓库中,你可以使用 Maven 命令 mvn install:install-file。你需要在命令中提供每个 JAR 文件的路径、groupId、artifactId、version 以及打包类型。

假设这三个 JAR 文件都在当前目录下,你可以使用以下命令将它们安装到本地 Maven 仓库中:

mvn install:install-file -Dfile=artemis-http-client-1.1.11.RELEASE.jar -DgroupId=com.hikvision.ga -DartifactId=artemis-http-client -Dversion=1.1.11.RELEASE -Dpackaging=jar
mvn install:install-file -Dfile=artemis-http-client-1.1.11.RELEASE-javadoc.jar -DgroupId=com.hikvision.ga -DartifactId=artemis-http-client -Dversion=1.1.11.RELEASE -Dpackaging=javadoc
mvn install:install-file -Dfile=artemis-http-client-1.1.11.RELEASE-sources.jar -DgroupId=com.hikvision.ga -DartifactId=artemis-http-client -Dversion=1.1.11.RELEASE -Dpackaging=sources
 

请注意,这里的 -Dfile 参数指定了要安装的文件的路径,-DgroupId-DartifactId-Dversion-Dpackaging 参数分别指定了依赖的 groupId、artifactId、版本和打包类型。根据你的实际情况,可能需要调整这些参数的值。

安装完成后,这些依赖将被复制到本地 Maven 仓库中,并可以在你的 Maven 项目中正常引用。

 在pom文件中修改,注意版本是这个1.1.11.RELEASE

<dependency> <groupId>com.hikvision.ga</groupId> <artifactId>artemis-http-client</artifactId> <version>1.1.11.RELEASE</version> </dependency>

仓库地址要改为你的本地仓库

<repositories> <repository> <id>local-repo</id> <url>file:///D:/repository/.m2/repository</url> </repository> </repositories>

修改好后右键maven 重载

3.修改maven编译插件。官方给我的编译插件有问题,编译后的jar中没有打包进入依赖。

我注释掉原来的build标签

   <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>ga.ArtemisPostTest</mainClass> <!-- 设置入口类 -->
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

修改好后右键maven 重载

4.修改java环境依赖

因为你本机和项目pom中配置的java版本不一致,要改为你真实的java版本,我这里装的是java17,我要改为java17

<properties>
<javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
<httpcomponents.version>4.5.14</httpcomponents.version>
<fastjson.version>1.2.83</fastjson.version>
<commons-lang3.version>3.12.0</commons-lang3.version>
<logback.version>1.2.11</logback.version>
<java.version>17</java.version>
</properties>

在项目结构中所有的java版本都要改为17,不在赘述

 

最终修改后的pom文件如下

<!-- Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with
  this work for additional information regarding copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations
  under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.hikvision.ga</groupId>
    <artifactId>artemis-http-client-demo</artifactId>
    <version>1.1.11</version>
    <packaging>jar</packaging>
    <name>artemis-http-client-demo</name>
    <description>hikvision open sdk</description>
    <url>hikvision-artemis-sdk</url>

    <properties>
        <javadocExecutable>${java.home}/../bin/javadoc</javadocExecutable>
        <httpcomponents.version>4.5.14</httpcomponents.version>
        <fastjson.version>1.2.83</fastjson.version>
        <commons-lang3.version>3.12.0</commons-lang3.version>
        <logback.version>1.2.11</logback.version>
        <java.version>17</java.version>
    </properties>

    <licenses>
        <license>
            <name>The Apache Software License, Version 2.0</name>
            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
            <distribution>repo</distribution>
        </license>
    </licenses>

    <scm>
        <url></url>
    </scm>

    <developers>
        <developer>
            <name>sky-lft</name>
        </developer>
    </developers>

    <dependencies>
        <dependency>
            <groupId>com.hikvision.ga</groupId>
            <artifactId>artemis-http-client</artifactId>
            <version>1.1.11.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>${httpcomponents.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpmime</artifactId>
            <version>${httpcomponents.version}</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>${fastjson.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>${commons-lang3.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-core</artifactId>
            <version>${logback.version}</version>
        </dependency>
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>${logback.version}</version>
        </dependency>
    </dependencies>
<!--    <build>-->
<!--        <plugins>-->
<!--            <plugin>-->
<!--                <artifactId>maven-compiler-plugin</artifactId>-->
<!--                <configuration>-->
<!--                    <source>17</source>-->
<!--                    <target>17</target>-->
<!--                    <encoding>UTF-8</encoding>-->
<!--                </configuration>-->
<!--            </plugin>-->
<!--            <plugin>-->
<!--                <groupId>org.apache.maven.plugins</groupId>-->
<!--                <artifactId>maven-source-plugin</artifactId>-->
<!--                <version>2.2.1</version>-->
<!--                <executions>-->
<!--                    <execution>-->
<!--                        <id>attach-sources</id>-->
<!--                        <goals>-->
<!--                            <goal>jar-no-fork</goal>-->
<!--                        </goals>-->
<!--                    </execution>-->
<!--                </executions>-->
<!--            </plugin>-->
<!--&lt;!&ndash;            <plugin>&ndash;&gt;-->
<!--&lt;!&ndash;                <groupId>org.apache.maven.plugins</groupId>&ndash;&gt;-->
<!--&lt;!&ndash;                <artifactId>maven-javadoc-plugin</artifactId>&ndash;&gt;-->
<!--&lt;!&ndash;                <version>2.10.3</version>&ndash;&gt;-->
<!--&lt;!&ndash;                <configuration>&ndash;&gt;-->
<!--&lt;!&ndash;                    <additionalparam>-Xdoclint:none</additionalparam>&ndash;&gt;-->
<!--&lt;!&ndash;                </configuration>&ndash;&gt;-->
<!--&lt;!&ndash;                <executions>&ndash;&gt;-->
<!--&lt;!&ndash;                    <execution>&ndash;&gt;-->
<!--&lt;!&ndash;                        <goals>&ndash;&gt;-->
<!--&lt;!&ndash;                            <goal>jar</goal>&ndash;&gt;-->
<!--&lt;!&ndash;                        </goals>&ndash;&gt;-->
<!--&lt;!&ndash;                    </execution>&ndash;&gt;-->
<!--&lt;!&ndash;                </executions>&ndash;&gt;-->
<!--&lt;!&ndash;            </plugin>&ndash;&gt;-->
<!--        </plugins>-->

<!--    </build>-->
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.3.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <archive>
                        <manifest>
                            <mainClass>ga.ArtemisPostTest</mainClass> <!-- 设置入口类 -->
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>local-repo</id>
            <url>file:///D:/repository/.m2/repository</url>
        </repository>
    </repositories>
</project>

 

posted on 2024-03-10 18:39  GKLBB  阅读(165)  评论(0编辑  收藏  举报