将 proto 文件转成 java 类

 

将 proto 文件转成 java 类:

将 proto 文件放在 /resource 目录下,执行 mvn package ,类会自动生成

 

<plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.11.4</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <protocVersion>${protobuf.version}</protocVersion>
                            <protocArtifact>com.google.protobuf:protoc:3.14.0:exe:osx-x86_64</protocArtifact>
                            <inputDirectories>
                                <include>src/main/resources/proto</include>
                            </inputDirectories>
                            <outputTargets>
                                <outputTarget>
                                    <type>java</type>
                                    <outputDirectory>src/main/java</outputDirectory>
                                </outputTarget>
                            </outputTargets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

 

posted on 2024-07-01 15:46  快鸟  阅读(76)  评论(0编辑  收藏  举报