标签:
新建一个 Maven 项目:
项目名称:
我们新建的空白 Maven 项目结构如下:
对Maven 项目来说,在 pom.xml 文件中需要增加对应 jar
<dependency> <groupId>io.grpc</groupId> <artifactId>grpc-all</artifactId> <version>0.13.2</version> </dependency>
导入 proto 插件
protobuf-maven-plugin:
https://www.xolstice.org/protobuf-maven-plugin/
修改 pom.xml 文件,增加下面节:
<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>
<!--
The version of protoc must match protobuf-java. If you don‘t depend on
protobuf-java directly, you will be transitively depending on the
protobuf-java version that grpc depends on.
-->
<protocArtifact>com.google.protobuf:protoc:3.0.0-beta-2:exe:${os.detected.classifier}</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:0.13.2:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
执行Maven插件命令。
在输出命令中,我们可以看到编译后的输出。
[INFO] --- protobuf-maven-plugin:0.5.0:compile (default-cli) @ myTestMaven ---
[INFO] Compiling 2 proto file(s) to /Users/ghj1976/project/mystudy/Demo1/target/generated-sources/protobuf/java
参考: https://github.com/grpc/grpc-java/blob/master/README.md
标签:
原文地址:http://www.cnblogs.com/ghj1976/p/5391205.html