天天看點

Grpc檔案生成java檔案的方法

Grpc檔案,結尾XXX..proto檔案

idea下載下傳插件:

Grpc檔案生成java檔案的方法

 建立一個maven項目

pom檔案加入配置

<dependencies>
    <dependency>
        <groupId>com.google.protobuf</groupId>
        <artifactId>protobuf-java</artifactId>
        <version>3.5.1</version>
    </dependency>
    <dependency>
        <groupId>io.grpc</groupId>
        <artifactId>grpc-all</artifactId>
        <version>1.12.0</version>
    </dependency>

</dependencies>
    <build>
        <extensions>
            <extension>
                <groupId>kr.motd.maven</groupId>
                <artifactId>os-maven-plugin</artifactId>
                <version>1.4.1.Final</version>
            </extension>
        </extensions>
        <plugins>
            <plugin>
                <groupId>org.xolstice.maven.plugins</groupId>
                <artifactId>protobuf-maven-plugin</artifactId>
                <version>0.5.0</version>
                <configuration>
                    <protocArtifact>com.google.protobuf:protoc:3.0.0:exe:${os.detected.classifier}</protocArtifact>
                    <pluginId>grpc-java</pluginId>
                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.0.0:exe:${os.detected.classifier}</pluginArtifact>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                            <goal>compile-custom</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
           

将你的proto檔案放到main下的檔案夾下,

Grpc檔案生成java檔案的方法

點選maven進行操作

Grpc檔案生成java檔案的方法

打包完畢項目輸出目錄

Grpc檔案生成java檔案的方法

 此jar包就是可以引用到項目中,這樣就可以放到用戶端,服務端去使用了,具體使用執行個體,我會在後面的文章裡進行舉例說明,稍安勿躁