简体   繁体   English

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

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

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 failed 错误:/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导出 JAVA_HOME=/opt/java/jdk1.7.0_67

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

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

but if I execute,但如果我执行,

sudo yum install protobuf-compiler sudo yum 安装 protobuf 编译器

it installs protobuf2.3 compiler and this particular error gets solved.它安装了 protobuf2.3 编译器,这个特定的错误得到了解决。 But since my pom file has protobuf 2.5.0, java abstract method error arises during the next compilation.但是由于我的pom文件是protobuf 2.5.0,下次编译的时候会出现java抽象方法错误 I'm stuck on how to proceed.我被困在如何继续。 I've spend many hrs in it, so any help is much appreciated.我在里面花了很多时间,所以非常感谢任何帮助。

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

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.我猜你设置了 LD_LIBRARY_PATH 来在你的环境设置中添加 /usr/local/lib 。 And it doesn't take effect when building project with maven/sbt and other build tools.并且在使用maven/sbt等构建工具构建项目时不生效。

Answer extracted from the Question (written by OP):从问题中提取的答案(由 OP 编写):

I solved it.我解决了。 I copied protoc file from /usr/local/lib to /usr/bin and it solved it.我将 protoc 文件从/usr/local/lib复制到/usr/bin并解决了它。

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

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