Protobuf plug-in use
In Netty development, protoc needs to be converted to java classes. The general approach is to execute protoc commands and convert .proto files into Java classes in turn
protoc.exe -I=d:/tmp --java_out=d:/tmp d:/tmp/monitor_data.proto
Today, we will introduce a quick correct posture to convert protobuf to java file. Just add the following configuration in our pom.xml, and then execute the compile command in maven to generate the response file
Note that
protoSourceRoot reads all proto in the resources directory (modify according to your preferences)
outputDirectory generates output java files are also stored in the resources directory (modify according to your preferences)
For other more parameters, please refer to the official document
https://www.xolstice.org/protobuf-maven-plugin/compile-mojo.html
<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.0</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.6.1:exe:${os.detected.classifier}</protocArtifact>
<pluginId>protoc-java</pluginId>
<!--读取proto文件路径-->
<protoSourceRoot>${project.basedir}/src/main/resources</protoSourceRoot>
<!--生产的java文件路径-->
<outputDirectory>${project.basedir}/src/main/resources/protobuf/entity</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Execution effect