因此,我尝试按照https://grpc.io/docs/tutorials/basic/java.html#generating-client-and-server-code的教程进行操作,但是在使用带有protoc编译器的grpc插件进行编译时遇到了麻烦。我已经使用插件正确设置了pom.xml(我认为),但是编译器不会生成该指南所需的文件(即RouteGuideGrpc.java)。
我目前正在使用“ mvn protobuf:compile”编译.proto
pom.xml:
<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.example</groupId>
<artifactId>maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.google.protobuf/protobuf-java -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.14.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.14.0</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.5.1</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.5.1-1:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.14.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
有人知道为什么会发生这种情况,还是知道如何将grpc插件添加到protobuf编译器?我没有正确安装插件吗?
btw:我是使用Maven的菜鸟。
答案 0 :(得分:0)
您的配置显示正确。但是,protobuf:compile
不运行任何协议插件(包括gRPC插件);这就是protobuf:compile-custom
的作用。
所以您只需要运行:
mvn protobuf:compile-custom
输出将放置在target/generated-sources/protobuf/grpc-java/
文件夹中。
答案 1 :(得分:0)
请检查您的存储空间是否足够用于目标文件。