New MAVEN Project
Create a new Maven project:
- The POM defines the smallest maven2 element, namely: Groupid,artifactid,version.
- GroupId: A unique flag for the project or organization, and the path generated by the configuration is also generated by this, as the relative path generated by Org.codehaus.mojo is:/org/codehaus/mojo
- Artifactid: The generic name of the project
- Version: Versions of projects
- Packaging: Packaged mechanisms such as POM, jar, Maven-plugin, EJB, War, Ear, RAR, par
- Classifier: Classification
Project Name:
Our new blank Maven project structure is as follows:
Import GRPC corresponding package dependencies
For MAVEN projects, you need to add the corresponding jar in the Pom.xml file
<dependency> <groupId>io.grpc</groupId> <artifactid>grpc-all</artifactid > <version>0.13.2</version></dependency>
Importing Proto Plugins
Importing Maven protobuf Plugins
Protobuf-maven-plugin:
https://www.xolstice.org/protobuf-maven-plugin/
To modify the Pom.xml file, add the following section:
<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'll be a 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>
Executes the MAVEN plug-in command.
In the output command, we can see the compiled output.
[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
Reference: HTTPS://GITHUB.COM/GRPC/GRPC-JAVA/BLOB/MASTER/README.MD
Maven project, compile the proto file into a Java class