2013-03-14 38 views
20

Tôi mới sử dụng Linux và Protobuf .. Tôi cần trợ giúp.Lỗi biên dịch Maven & Protobuf: Không thể tìm thấy biểu tượng trong gói com.google.protobuf

Tôi đang cố gắng để "mvn gói" một dự án có chứa nhiều ".proto" tác phẩm, và một tập tin pom.xml tất nhiên ...

Tôi đang làm việc trên Ubuntu

= ======================================

ERROR

Khi tôi chạy "gói mvn", tôi nhận được lỗi này:

sau

... 
Compiling 11 source files to .../target/classes 
... 

tôi nhận được một bó của các lỗi này:

[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

Dưới đây là file pom.xml, với groupId & artifactId đưa ra:

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

=======================================

Protobuf LẮP ĐẶT

tôi đã thực hiện

./configure 
make 
make check 
make install 

trong protobuf /,

mvn test 
mvn install 
mvn package 

trong protobuf/java.

Tôi đã jar trong protobuf/java/target

và thêm nó vào repo maven của tôi bằng cách chạy:

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 

Lưu ý rằng tôi đã sai lầm xung quanh với $ LD_LIBRARY_PATH. Hiện tại khi tôi chạy nó, tôi nhận được:

/usr/local/lib/:/usr/:/usr/lib/:/usr/local/ 

yeah ....như bạn có thể nói tôi không có một đầu mối về việc thiết $ LD_LIBRARY_PATH

Tôi cũng chạy:

apt-get install protobuf-compiler 

==================== ===================

pROTOC LẮP ĐẶT

tôi quên những gì tôi đã làm để làm cho công việc protoc, nhưng khi tôi chạy

protoc --version 

Tôi nhận được

libprotoc 2.5.0 

=======================================

Câu hỏi của tôi cũng tương tự như:

Problems using protobufs with java and scala

maven compilation failure

============================== =========

TIN NHẮN CÓ THỂ CE?

still not find package, after 'mvn install'

http://www.scriptol.com/programming/protocol-buffers-tutorial.php

bất cứ ai có thể giúp đỡ?

=======================================

TIẾN

Rõ ràng đó là một thất bại plugin:

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: 
+4

+1 Thành phần câu hỏi hay. –

Trả lời

11

tôi đã cùng một vấn đề. tạo nguồn protobuf từ google trực tiếp (Tôi đã sử dụng 2.5.0) và làm

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 

khắc phục sự cố cho tôi.

Trong các thử nghiệm trước đây của tôi, tôi nhận thấy rằng tệp jar trong /root/.m2/repository/com/google/protobuf/protobuf-java/2.5.0/ bị thiếu.

Có thể thử sử dụng phiên bản 2.5.0 trong tệp pom.xml và/hoặc sao chép thủ công một cách thủ công.

cổ vũ

+5

Yup! Thay đổi 2.4.1 thành 2.5.0 đã hoạt động! Cảm ơn bạn! – Kayvar

+0

Thay đổi 2.4.1 thành 2.5.0 trong pom của tôi đã giải quyết được vấn đề của tôi cũng như – gnielsen

8

Tôi gặp sự cố này khi có sự không khớp giữa phiên bản protoc được cài đặt và phiên bản được liệt kê trong pom. Phù hợp với các phiên bản đã khắc phục sự cố. Trong trường hợp của tôi, tôi phải chuyển phiên bản protoc của tôi về 2.4.1 để phù hợp với POM.

8

protoc --version phải có cùng phiên bản như được đặt trong pom.xml tệp (protobuf-java-2.5.0.jar).

+0

Đây là giải pháp đơn giản nhất đối với tôi! – santon

+0

tuyệt vời, cảm ơn bạn. – idmitriev

1

Vấn đề của tôi là một lớp mở rộng thử nghiệm đơn vị từ thư mục chính. Tôi đã giải quyết vấn đề với:

<!-- Allow tests to call classes in main folder --> 

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>build-helper-maven-plugin</artifactId> 
    <version>1.9.1</version> 
    <executions> 
     <execution> 
      <id>add-source</id> 
      <phase>generate-sources</phase> 
      <goals> 
       <goal>add-source</goal> 
      </goals> 
      <configuration> 
       <sources> 
        <source>src/test/java</source> 
        <source>src/main/java</source> 
       </sources> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
Các vấn đề liên quan