2020-07-02 mvn打包hmac sdk项目为一个jar

2020-07-02  本文已影响0人  五大RobertWu伍洋

hmac java sdk项目的pom.xml中使用如下插件:

            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <!--这部分可有可无,加上的话则直接生成可运行jar包-->
                    <!--<archive>-->
                    <!--<manifest>-->
                    <!--<mainClass>${exec.mainClass}</mainClass>-->
                    <!--</manifest>-->
                    <!--</archive>-->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
            </plugin>

然后执行``, 或者在idea的mvn工具窗口选择Plugins->assembly->assembly:assembly,执行build

最终会看到生成了两个jar包

hmac-auth-1.0-SNAPSHOT.jar
hmac-auth-1.0-SNAPSHOT-jar-with-dependencies.jar

前者只包含项目代码,后者包含了项目依赖的jar包资源。比如okttp.

再次编译和运行测试hamc sdk的java code,只需要指定一个依赖的jar包了

G:\Projects\github\hmac-auth-java-sdk\hmac-auth\src\main\java>javac -cp %CLASSPATH%;G:\Projects\github\hmac-auth-java-sdk\hmac-auth\target\hmac-auth-1.0-SNAPSHOT-jar-with-dependencies.jar HmacTestEasy2.java

G:\Projects\github\hmac-auth-java-sdk\hmac-auth\src\main\java>java -cp %CLASSPATH%;G:\Projects\github\hmac-auth-java-sdk\hmac-auth\target\hmac-auth-1.0-SNAPSHOT-jar-with-dependencies.jar HmacTestEasy2
X-Date: Thu, 02 Jul 2020 07:39:06 GMT
Content-md5: Xyt1XD8MNZHo0CqYKWINnA==
Authorization: hmac username="1533661890@qq.com",algorithm="hmac-sha256",headers="X-Date Content-md5 request-line",signature="ZEqMKb0eqq8gL4Yi4RI/UX7t5Wjr3GuS6IDx5IgBN/Q="
Response Code: 200
Response Body: {"code":200102,"message":"查询数据成功","currentPageNum":1,"totalpage":4,"data":[{"app":"392500662","logTimestamp":"2020-03-05 23:11:57.5310000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:12:07.8080000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:12:57.5370000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:13:21.9730000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:14:24.0070000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:19:14.7320000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":null,"function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:19:53.6760000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-05 23:40:13.0110000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-06 09:42:49.7440000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"},{"app":"392500662","logTimestamp":"2020-03-06 09:43:13.0940000","uid":"wufa1992love","keyWords":"awk","bodyMessage":"gotodownload","os":"linux","functionName":"clickAd","function":null,"action":"activate","device":"iphone11","eventTimestamp":"2020-03-05 22:32:29.0000000"}]}

使用相对路劲编译和运行则也是成功的:

G:\Projects\github\hmac-auth-java-sdk\hmac-auth\src\main\java>javac -cp %CLASSPATH%;..\..\..\target\hmac-auth-1.0-SNAPSHOT-jar-with-dependencies.jar HmacTestEasy2.java

G:\Projects\github\hmac-auth-java-sdk\hmac-auth\src\main\java>java -cp %CLASSPATH%;..\..\..\target\hmac-auth-1.0-SNAPSHOT-jar-with-dependencies.jar HmacTestEasy2
上一篇下一篇

猜你喜欢

热点阅读