1 <build> 2 <plugins> 3 <plugin> 4 <groupId>com.github.os72</groupId> 5 <artifactId>protoc-jar-maven-plugin</artifactId> 6 <version>3.11.1</version> <!-- 替换为您需要的Protocol Buffers版本 --> 7 <executions> 8 <execution> 9 <goals> 10 <goal>run</goal> 11 </goals> 12 <phase>generate-sources</phase> 13 </execution> 14 </executions> 15 <configuration> 16 <inputDirectories> 17 <include>src/main/proto</include> <!-- 您的.proto文件所在的目录 --> 18 </inputDirectories> 19 <outputTargets> 20 <outputTarget> 21 <type>java</type> 22 <outputDirectory>src/main/java</outputDirectory> <!-- 生成的Java文件存放的目录 --> 23 </outputTarget> 24 </outputTargets> 25 </configuration> 26 </plugin> 27 </plugins> 28 </build>
1 mvn clean install
就可以显示了
1 syntax = "proto3"; 2 package org.example; 3 message Person { 4 string name = 1; 5 int32 age = 2; 6 }
这是proto的代码
1 <?xml version="1.0" encoding="UTF-8"?> 2 <project xmlns="http://maven.apache.org/POM/4.0.0" 3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 5 <modelVersion>4.0.0</modelVersion> 6 7 <repositories> 8 <repository> 9 <id>central</id> 10 <url>https://repo.maven.apache.org/maven2</url> 11 </repository> 12 </repositories> 13 14 <groupId>org.example</groupId> 15 <artifactId>Task2</artifactId> 16 <version>1.0-SNAPSHOT</version> 17 18 <properties> 19 <maven.compiler.source>8</maven.compiler.source> 20 <maven.compiler.target>8</maven.compiler.target> 21 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 22 </properties> 23 24 <dependencies> 25 <dependency> 26 <groupId>com.google.protobuf</groupId> 27 <artifactId>protobuf-java</artifactId> 28 <version>3.19.6</version> <!-- 使用最新的版本 --> 29 </dependency> 30 31 </dependencies> 32 33 <build> 34 <plugins> 35 <plugin> 36 <groupId>com.github.os72</groupId> 37 <artifactId>protoc-jar-maven-plugin</artifactId> 38 <version>3.11.1</version> <!-- 替换为您需要的Protocol Buffers版本 --> 39 <executions> 40 <execution> 41 <goals> 42 <goal>run</goal> 43 </goals> 44 <phase>generate-sources</phase> 45 </execution> 46 </executions> 47 <configuration> 48 <inputDirectories> 49 <include>src/main/proto</include> <!-- 您的.proto文件所在的目录 --> 50 </inputDirectories> 51 <outputTargets> 52 <outputTarget> 53 <type>java</type> 54 <outputDirectory>src/main/java</outputDirectory> <!-- 生成的Java文件存放的目录 --> 55 </outputTarget> 56 </outputTargets> 57 </configuration> 58 </plugin> 59 </plugins> 60 </build> 61 62 </project>
完整的pom.xml
© 版权声明
THE END
喜欢就支持一下吧