protobuf-maven-plugin使用
时间: 2023-12-08 17:38:38 浏览: 39
protobuf-maven-plugin是一个Maven插件,用于将Protocol Buffers文件编译为Java类。以下是protobuf-maven-plugin的使用方法:
1.在pom.xml文件中添加以下插件配置:
```xml
<build>
<plugins>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>0.6.1</version>
<configuration>
<protocExecutable>/usr/local/bin/protoc</protocExecutable>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
<goal>test-compile</goal>
<goal>test-compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
```
2.在src/main/proto目录下创建.proto文件,例如:
```protobuf
syntax = "proto3";
package com.example;
message Person {
string name = 1;
int32 age = 2;
}
```
3.运行以下命令编译.proto文件:
```shell
mvn protobuf:compile
```
4.编译后的Java类将生成在target/generated-sources/protobuf/java目录下。