如何將本地jar包安裝到maven倉庫
阿新 • • 發佈:2022-04-15
1.idea拉取專案。
https://github.com/edap-io/edap.git
2.執行命令進行打包
進入該服務的目錄,執行如下命令
mvn clean install -DskipTests=true
如果該命令匯入的包有問題,換個命令
mvn install:install-file -DgroupId="io.edap" -DartifactId=edap-protobuf-wire -Dversion="0.1-SNAPSHOT" -Dpackaging=jar -Dfile=G:\IdeaProjects\edap\edap-protobuf-wire\target\edap-protobuf-wire-0.1-SNAPSHOT.jar
3.構建服務看看自己的包是否好用
建立一個springboot專案,把該包匯入進行,pom如下
<?xml version="1.0" encoding="UTF-8"?> <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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.6.6</version> <relativePath/> <!-- lookup parent fromrepository --> </parent> <groupId>com.example</groupId> <artifactId>protobuf-edap-study</artifactId> <version>0.0.1-SNAPSHOT</version> <name>protobuf-edap-study</name> <description>protobuf-edap-study</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>io.edap</groupId> <artifactId>edap-protobuf</artifactId> <version>0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>io.edap</groupId> <artifactId>edap-bean-convert</artifactId> <version>0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.ow2.asm</groupId> <artifactId>asm-all</artifactId> <version>5.0.3</version> </dependency> <dependency> <groupId>io.edap</groupId> <artifactId>edap-protobuf-wire</artifactId> <version>0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>io.edap</groupId> <artifactId>edap-common</artifactId> <version>0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>
測試
package com.example.protobufedapstudy.bean; import io.edap.protobuf.ProtoBuf; /** * @Author: chenjie * @Date: 2022/4/15 11:48 * @Description: */ public class StudyEdap { public static void main(String[] args) { User user = new User(); user.setUid(10000L); user.setUsername("louis"); //將Javabean序列化為protobuf的二進位制資料 byte[] bs = ProtoBuf.toByteArray(user); //將protobuf協議的資料反序列化為java物件 User userInfo = ProtoBuf.toObject( bs, User.class); System.out.println(userInfo); } }
4.執行結果
正常顯示