gpt4 book ai didi

java - Protocol Buffer 编译器maven插件

转载 作者:搜寻专家 更新时间:2023-10-31 08:22:54 24 4
gpt4 key购买 nike

我在我的 POM 中配置了 Protocol Buffer 编译器插件,每当构建项目时都会执行该插件。这个编译器插件在 Windows 中运行良好,但现在我将我的项目移到了 ubuntu PC 上,需要为此使用合适的替代方案。

        <plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>compile-protoc</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="src/main/resources/protocolBuffers/compiled" />
<path id="proto.path">
<fileset dir="src/main/proto">
<include name="**/*.proto" />
</fileset>
</path>
<pathconvert pathsep=" " property="proto.files" refid="proto.path" />
<exec executable="src/main/resources/protocolBuffers/compiler/protoc" failonerror="true">
<arg value="--java_out=src/main/resources/" />
<arg value="-I${project.basedir}/" />
<arg line="${proto.files}"/>
</exec>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

我在 Ubuntu netbeans 中尝试构建项目时看到以下输出

--- maven-antrun-plugin:1.3:run (compile-protoc) @ Px10App ---
Executing tasks
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 5.638s
Finished at: Tue Mar 25
Final Memory: 9M/105M
------------------------------------------------------------------------
Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.3:run (compile-protoc) on project Px10App: An Ant BuildException has occured: Execute failed: java.io.IOException: Cannot run program "src/main/resources/protocolBuffers/compiler/protoc": error=2, No such file or directory -> [Help 1]

如何使编译器插件在 Ubuntu netbeans 中工作?

最佳答案

这个带有内置的 protoc(它最初基于 igor-petruk/protobuf-maven-plugin,但它带有为 Linux、Mac/OSX 和 Windows 捆绑的 protoc 二进制文件)。在运行时它检测平台并执行相应的二进制文件

https://github.com/os72/protoc-jar-maven-plugin

这是一个例子:

<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.11.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<protocVersion>2.4.1</protocVersion>
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
</configuration>
</execution>
</executions>
</plugin>

关于java - Protocol Buffer 编译器maven插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620300/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com