Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create protodef Person instance #56

Open
beatlevic opened this issue Jun 23, 2015 · 3 comments
Open

Cannot create protodef Person instance #56

beatlevic opened this issue Jun 23, 2015 · 3 comments

Comments

@beatlevic
Copy link

I followed the Person example and failed to create a protobuf instance. I'm running on OSX Mavericks.

lein --version
Leiningen 2.3.4 on Java 1.7.0_55 Java HotSpot(TM) 64-Bit Server VM

I have the following project.clj:

(defproject my-project "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME"
  :license {:name "Eclipse Public License"
            :url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.7.0-RC1"]
                 [org.flatland/protobuf "0.7.1"]
                 [org.clojure/data.codec "0.1.0"]]
  :main ^:skip-aot my-project.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}}
  :global-vars {*print-length* 100}
  :plugins [[lein-protobuf "0.4.3"]]
  :resource-paths ["resources/protobuf-java-2.6.1.jar"])

As you can see I installed protobuf 2.6.1 manually and included the jar in the resource-path.

I use the following person.proto file in resources/proto:

message Person {
  required int32  id    = 1;
  required string name  = 2;
  optional string email = 3;
  repeated string likes = 4;
}

Running "lein protobuf" works and correctly creates PersonOuterClass.java in the target/protosrc

Loading the namespace also works:

(ns my-project.proto
  (:use flatland.protobuf.core)
  (:import PersonOuterClass$Person))

Next up in the cider-repl (0.9.0):

(def Person (protodef PersonOuterClass$Person)); => #'my-project.proto/Person

And then the error when:

(def p (protobuf Person :id 4 :name "Bob" :email "[email protected]"))
CompilerException java.lang.NoSuchMethodError: com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(Lcom/google/protobuf/GeneratedMessage$GeneratedExtension;)Ljava/lang/Object;, compiling:(form-init5554068261882864915.clj:1:8) 

More details:

2. Unhandled clojure.lang.Compiler$CompilerException
   Error compiling: form-init5554068261882864915.clj:1:8

                 Compiler.java: 3628  clojure.lang.Compiler$InvokeExpr/eval
                 Compiler.java:  439  clojure.lang.Compiler$DefExpr/eval
                 Compiler.java: 6797  clojure.lang.Compiler/eval
                 Compiler.java: 6755  clojure.lang.Compiler/eval
                      core.clj: 3079  clojure.core/eval
                      main.clj:  240  clojure.main/repl/read-eval-print/fn
                      main.clj:  240  clojure.main/repl/read-eval-print
                      main.clj:  258  clojure.main/repl/fn
                      main.clj:  258  clojure.main/repl
                   RestFn.java: 1523  clojure.lang.RestFn/invoke
        interruptible_eval.clj:   58  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                      AFn.java:  152  clojure.lang.AFn/applyToHelper
                      AFn.java:  144  clojure.lang.AFn/applyTo
                      core.clj:  628  clojure.core/apply
                      core.clj: 1866  clojure.core/with-bindings*
                   RestFn.java:  425  clojure.lang.RestFn/invoke
        interruptible_eval.clj:   56  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
        interruptible_eval.clj:  188  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
        interruptible_eval.clj:  157  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                      AFn.java:   22  clojure.lang.AFn/run
       ThreadPoolExecutor.java: 1145  java.util.concurrent.ThreadPoolExecutor/runWorker
       ThreadPoolExecutor.java:  615  java.util.concurrent.ThreadPoolExecutor$Worker/run
                   Thread.java:  745  java.lang.Thread/run

1. Caused by java.lang.NoSuchMethodError
   com.google.protobuf.DescriptorProtos$FieldOptions.getExtension(Lcom/google/protobuf/GeneratedMessage$GeneratedExtension;)Ljava/lang/Object;

PersistentProtocolBufferMap.java:  581  flatland.protobuf.PersistentProtocolBufferMap/addField
PersistentProtocolBufferMap.java:  735  flatland.protobuf.PersistentProtocolBufferMap/cons
PersistentProtocolBufferMap.java:  286  flatland.protobuf.PersistentProtocolBufferMap/construct
                      core.clj:   46  flatland.protobuf.core/protobuf
                   RestFn.java:  146  clojure.lang.RestFn/applyTo
                 Compiler.java: 3623  clojure.lang.Compiler$InvokeExpr/eval
                 Compiler.java:  439  clojure.lang.Compiler$DefExpr/eval
                 Compiler.java: 6797  clojure.lang.Compiler/eval
                 Compiler.java: 6755  clojure.lang.Compiler/eval
                      core.clj: 3079  clojure.core/eval
                      main.clj:  240  clojure.main/repl/read-eval-print/fn
                      main.clj:  240  clojure.main/repl/read-eval-print
                      main.clj:  258  clojure.main/repl/fn
                      main.clj:  258  clojure.main/repl
                   RestFn.java: 1523  clojure.lang.RestFn/invoke
        interruptible_eval.clj:   58  clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn
                      AFn.java:  152  clojure.lang.AFn/applyToHelper
                      AFn.java:  144  clojure.lang.AFn/applyTo
                      core.clj:  628  clojure.core/apply
                      core.clj: 1866  clojure.core/with-bindings*
                   RestFn.java:  425  clojure.lang.RestFn/invoke
        interruptible_eval.clj:   56  clojure.tools.nrepl.middleware.interruptible-eval/evaluate
        interruptible_eval.clj:  188  clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn/fn
        interruptible_eval.clj:  157  clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn
                      AFn.java:   22  clojure.lang.AFn/run
       ThreadPoolExecutor.java: 1145  java.util.concurrent.ThreadPoolExecutor/runWorker
       ThreadPoolExecutor.java:  615  java.util.concurrent.ThreadPoolExecutor$Worker/run
                   Thread.java:  745  java.lang.Thread/run

I also get the same error when I drop the "repeated string likes" from the Person.proto.

Any idea what is causing this?

@quan-nh
Copy link

quan-nh commented Aug 2, 2015

@shengdoushi
Copy link

how to solve this problem ??? i also place protobuf java-files into my project, but it not works :

protoc --java_out=src/main/java -I../src ../src/google/protobuf/descriptor.proto

then copy java-files to my project src-ivm directory:

:java-source-paths ["src-jvm"]

src-jvm/com/google/....

@shengdoushi
Copy link

I solved!!!
Please use correct version:

org.flatland/protobuf "0.8.2-SNAPSHOT"
com.google.protobuf/protobuf-java "2.5.0"

lein-protobuf "0.4.1"

That's all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants