简体   繁体   中英

How to build Protobuf for Java in Windows via Eclipse

I download the source Protobuf zip file. Then I open up my Classic Eclipse and choose File->Import->Existing Maven Projects.

I choose the root folder to be /java. It shows that pom.xml has been ticked, choose Next.

The screen says: Setup Maven plugin connectors: with

maven-antrun-plugin:1.3:run (2 errors):
No marketplace entries found to handle maven-antrun-plugin:1.3:run in Eclipse. Please see Help for more information.

Am I missing something here?

You can ignore that error. But when the import process finish probably you will get:

Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-antrun-plugin:1.3:run (execution: generate-sources, phase: generate-sources)

If so, reason is that your current configuration doesn't support maven-antrun. You can find a related question here: How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds

An explanation of the problem can be found here: http://wiki.eclipse.org/M2E_plugin_execution_not_covered

Easy way to solve? Adding the next block of code to your pom.xml:

<pluginManagement>
  <plugins>
    <plugin>
      <groupId>org.eclipse.m2e</groupId>
      <artifactId>lifecycle-mapping</artifactId>
      <version>1.0.0</version>
      <configuration>
        <lifecycleMappingMetadata>
          <pluginExecutions>
            <pluginExecution>
              <pluginExecutionFilter>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <versionRange>[1.0.0,)</versionRange>
                <goals>
                  <goal>run</goal>
                </goals>
              </pluginExecutionFilter>
              <action>
                <execute>
                  <runOnIncremental>false</runOnIncremental>
                </execute>
              </action>
            </pluginExecution>
          </pluginExecutions>
        </lifecycleMappingMetadata>
      </configuration>
    </plugin>
  </plugins>
</pluginManagement>

After some usual update Maven project configuration, clear and rebuild all, pom problem disappear.

But then you will get probably some error about missing classes. You must download the protoc binary and execute it for all the .proto files you can find on your sources directory. Example:

protoc --java_out=src/main/java -I../src ..\ src\google\protobuf\descriptor.proto

Below is a bash script to help you compile all of those proto files. Execute the script in the java directory.

#/bin/bash
for proto_file in ../src/google/protobuf/*.proto; do
    echo "generating java source from $proto_file"
    protoc --java_out=core/src/main/java -I../src $proto_file
done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM