Maven project, compile the proto file into a Java class

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.