Maven& Protobuf编译错误:无法在com.google.protobuf包中找到符号 [英] Maven & Protobuf compile error: Cannot find symbol in package com.google.protobuf
问题描述
我是Linux和Protobuf的新手......我需要帮助。
I'm new to Linux and Protobuf.. I need help.
我正在尝试mvn package一个包含许多.proto文件的项目,当然还有一个pom.xml文件......
I'm trying to "mvn package" a project that contains many ".proto" files, and a pom.xml file of course...
我正在研究Ubuntu
I'm working on Ubuntu
================== =====================
=======================================
当我运行mvn package时,我收到此错误:
When I run "mvn package", I receive this error:
...
Compiling 11 source files to .../target/classes
...
我收到了很多这样的错误:
I get a bunch of these errors:
[ERROR] .../target/generated-sources/...java:[16457,30] cannot find symbol
[ERROR] symbol : class Parser
[ERROR] location: package com.google.protobuf
[ERROR]
[ERROR] .../target/generated-sources/...java:[17154,37] cannot find symbol
[ERROR] symbol : class Parser
[ERROR] location: package com.google.protobuf
[ERROR]
[ERROR] .../target/generated-sources/...java:[17165,30] cannot find symbol
[ERROR] symbol : class Parser
[ERROR] location: package com.google.protobuf
[ERROR]
[ERROR] .../target/generated-sources/...java:[17909,37] cannot find symbol
[ERROR] symbol : class Parser
[ERROR] location: package com.google.protobuf
[ERROR]
==================================== ===
=======================================
这是pom.xml文件,包含groupId& artifactId取出:
Here is the pom.xml file, with groupId & artifactId taken out:
<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>*****</groupId>
<artifactId>*****</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>*****</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<proto.cas.path>${project.basedir}/src</proto.cas.path>
<target.gen.source.path>${project.basedir}/target/generated-sources</target.gen.source.path>
</properties>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.4.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<includes><include>**/commonapps/**</include></includes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<tasks>
<mkdir dir="${target.gen.source.path}" />
<path id="proto.path.files">
<fileset dir="${proto.cas.path}">
<include name="*.proto" />
</fileset>
</path>
<pathconvert pathsep=" " property="proto.files" refid="proto.path.files" />
<exec executable="protoc">
<arg value="--java_out=${target.gen.source.path}" />
<arg value="--proto_path=${proto.cas.path}" />
<arg line="${proto.files}" />
</exec>
</tasks>
<sourceRoot>${target.gen.source.path}</sourceRoot>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
====== =================================
=======================================
我已经完成了
./configure
make
make check
make install
in protobuf /,
in protobuf/,
和
mvn test
mvn install
mvn package
protobuf / java中的
。
in protobuf/java.
I在protobuf / java / target
I took the jar in protobuf/java/target
中取出jar并通过运行将其添加到我的maven仓库:
and added it to my maven repo by running:
mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=com.google.protobuf -DartifactId=protobuf-java -Dfile=protobuf-java-2.4.1.jar -Dversion=2.4.1
请注意,我已经弄乱了$ LD_LIBRARY_PATH。目前当我运行echo它时,我得到:
Note that I've messed around with $LD_LIBRARY_PATH. Currently when I run echo it, I get:
/usr/local/lib/:/usr/:/usr/lib/:/usr/local/
是的....你可以告诉我没有关于设置$ LD_LIBRARY_PATH的线索
yeah.... as you can tell I don't have a clue about setting $LD_LIBRARY_PATH
我还跑了:
apt-get install protobuf-compiler
=============== ========================
=======================================
我忘记了我做protoc的工作,但是当我运行时
I forgot what I did to make protoc work, but when I run
protoc --version
我得到
libprotoc 2.5.0
============== =========================
=======================================
======================= ================
=======================================
< 'mvn install'之后仍然找不到包
still not find package, after 'mvn install'
http://www.scriptol。 com / programming / protocol-buffers-tutorial.php
有人可以帮忙吗?
= ======================================
=======================================
显然这是一个插件失败:
Apparently it's a plugin failure:
https://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.0.2:compile (default-compile) on project casprotobuf: Compilation failure: Compilation failure:
推荐答案
我遇到了同样的问题。
直接从google构建protobuf源代码(我使用2.5.0)并执行
I had the same problem. building the protobuf sources from google directly (I used 2.5.0) and doing
mvn install:install-file -Dpackaging=jar -DgeneratePom=true -DgroupId=com.google.protobuf -DartifactId=protobuf-java -Dfile=protobuf-java-2.5.0.jar -Dversion=2.5.0
为我解决了这个问题。
在我之前的试验中,我注意到,那个罐子缺少/root/.m2/repository/com/google/protobuf/protobuf-java/2.5.0/中的文件。
In my earlier trials I noticed, that the jar-file in /root/.m2/repository/com/google/protobuf/protobuf-java/2.5.0/ was missing.
也许尝试使用2.5版本。 pom.xml中的0和/或手动复制jarfile。
Maybe try to use version 2.5.0 in the pom.xml and/or copying the jarfile manually.
欢呼
这篇关于Maven& Protobuf编译错误:无法在com.google.protobuf包中找到符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!