简体   繁体   English

如何通过Eclipse在Windows中为Java构建Protobuf

[英]How to build Protobuf for Java in Windows via Eclipse

I download the source Protobuf zip file. 我下载了Protobuf源zip文件。 Then I open up my Classic Eclipse and choose File->Import->Existing Maven Projects. 然后打开我的Classic Eclipse,然后选择File-> Import-> Existing Maven Projects。

I choose the root folder to be /java. 我选择根文件夹为/ java。 It shows that pom.xml has been ticked, choose Next. 它显示pom.xml已被勾选,选择Next。

The screen says: Setup Maven plugin connectors: with 屏幕上显示:安装Maven插件连接器:

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) 生命周期配置未涵盖的插件执行:org.apache.maven.plugins:maven-antrun-plugin:1.3:run(执行:generate-sources,阶段:generate-sources)

If so, reason is that your current configuration doesn't support maven-antrun. 如果是这样,原因是您当前的配置不支持maven-antrun。 You can find a related question here: How to solve "Plugin execution not covered by lifecycle configuration" for Spring Data Maven Builds 您可以在此处找到一个相关的问题: 如何解决Spring Data Maven Builds的“生命周期配置未涵盖的插件执行”

An explanation of the problem can be found here: http://wiki.eclipse.org/M2E_plugin_execution_not_covered 有关此问题的说明,请参见: http : //wiki.eclipse.org/M2E_plugin_execution_not_covered

Easy way to solve? 简单的解决方法? Adding the next block of code to your pom.xml: 将下一个代码块添加到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. 经过一些常规的Maven项目配置更新后,清除并重新生成所有文件,pom问题消失了。

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. 您必须下载协议二进制文件,并对在源目录中可以找到的所有 .proto文件执行该文件。 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. 下面是一个bash脚本,可帮助您编译所有这些原始文件。 Execute the script in the java directory. 在java目录中执行脚本。

#/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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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