java 如何解决/bin/sh: protoc: command not found?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30914623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:49:32  来源:igfitidea点击:

how to solve /bin/sh: protoc: command not found?

javamaven-3protocol-buffers

提问by midNight

I have installed protobuf 2.5.0 in my CentOs,

我已经在我的 CentOs 中安装了 protobuf 2.5.0,

when i execute the command protoc --version, it yields

当我执行命令protoc --version 时,它会产生

libprotoc 2.5.0

库协议 2.5.0

as output.

作为输出。

but Once I have pulled code from git and when I try to compile it using Maven3, the proto module throws error saying,

但是一旦我从 git 中提取代码并且当我尝试使用 Maven3 编译它时,proto 模块就会抛出错误说,

protoc failed error: /bin/sh: protoc: command not found

protoc 失败错误:/bin/sh: protoc: command not found

I refereed many blogs and also did try to change my bashrc path as follows,

我参考了很多博客,也确实尝试如下更改我的 bashrc 路径,

export JAVA_HOME=/opt/java/jdk1.7.0_67

export PATH=$PATH:/opt/java/jdk1.7.0_67/bin

export PATH=$PATH:/usr/local/lib

导出 JAVA_HOME=/opt/java/jdk1.7.0_67

导出 PATH=$PATH:/opt/java/jdk1.7.0_67/bin

导出 PATH=$PATH:/usr/local/lib

but if I execute,

但如果我执行,

sudo yum install protobuf-compiler

须藤 yum 安装 protobuf 编译器

it installs protobuf2.3 compiler and this particular error gets solved. But since my pom file has protobuf 2.5.0, java abstract method errorarises during the next compilation. I'm stuck on how to proceed. I've spend many hrs in it, so any help is much appreciated.

它安装了 protobuf2.3 编译器,这个特定的错误得到了解决。但是由于我的pom文件是protobuf 2.5.0,下次编译的时候会出现java抽象方法错误。我被困在如何继续。我在里面花了很多时间,所以非常感谢任何帮助。

my pom file for the proto module,

我的 proto 模块的 pom 文件,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <artifactId>GradPower</artifactId>
        <groupId>org.screative.gardpower</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <groupId>proto</groupId>
    <artifactId>proto</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    </properties>
    <dependencies>
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>2.5.0</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>com.google.protobuf.tools</groupId>
                <artifactId>maven-protoc-plugin</artifactId>
                <version>0.1.10</version>
                <configuration>
                    <protocExecutable>protoc</protocExecutable>
                    <protoSourceRoot>${project.basedir}/src/main/proto/</protoSourceRoot>

                    <languageSpecifications>
                        <LanguageSpecification>
                            <language>JAVA</language>
                            <outputDirectory>
                                ${project.basedir}/target/generated-sources/protoc
                            </outputDirectory>
                        </LanguageSpecification>
                    </languageSpecifications>

                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>compile</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                    <compilerArgument></compilerArgument>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <pluginRepositories>
        <pluginRepository>
            <id>dtrott</id>
            <url>http://maven.davidtrott.com/repository</url>
        </pluginRepository>
    </pluginRepositories>



</project>

Thanks in advance.

提前致谢。

EDIT: I solved it. I copied protoc file from /usr/local/lib to /usr/bin

编辑:我解决了它。我将 protoc 文件从 /usr/local/lib 复制到 /usr/bin

and it solved it. A silly mistake :P

它解决了它。一个愚蠢的错误:P

回答by Jared

You should run 'sudo ldconfig' to finish the installation.

您应该运行“sudo ldconfig”来完成安装。

I guessed you set LD_LIBRARY_PATH to add /usr/local/lib in your environment setting. And it doesn't take effect when building project with maven/sbt and other build tools.

我猜你设置了 LD_LIBRARY_PATH 来在你的环境设置中添加 /usr/local/lib 。并且在使用maven/sbt等构建工具构建项目时不生效。

回答by zohar

Answer extracted from the Question (written by OP):

从问题中提取的答案(由 OP 编写):

I solved it. I copied protoc file from /usr/local/libto /usr/binand it solved it.

我解决了。我从/usr/local/libto复制了 protoc 文件/usr/bin,它解决了它。