grpc java maven_gRPC

最近的项目需要java和python之间的进程通信,想到了之前使用过的的grpc.

JDK: version 7 or higher

看起来只依赖jdk,美滋滋

然后按照文档执行

./gradlew installDist

报错:

Shell

Task :grpc-compiler:compileJava_pluginExecutableJava_pluginCpp FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':grpc-compiler:compileJava_pluginExecutableJava_pluginCpp'.

> No tool chain is available to build for platform 'x86_64':

- Tool chain 'visualCpp' (Visual Studio): Visual Studio is not available on this operating system.

- Tool chain 'gcc' (GNU GCC): Could not determine GCC metadata: could not find vendor in output of /usr/local/gcc-4.9.4/bin/gcc.

- Tool chain 'clang' (Clang): Could not find C compiler 'clang' in system path.

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3m 47s

~

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

Task:grpc-compiler:compileJava_pluginExecutableJava_pluginCppFAILED

FAILURE:Buildfailedwithanexception.

*Whatwentwrong:

Executionfailedfortask':grpc-compiler:compileJava_pluginExecutableJava_pluginCpp'.

>Notoolchainisavailabletobuildforplatform'x86_64':

-Toolchain'visualCpp'(VisualStudio):VisualStudioisnotavailableonthisoperatingsystem.

-Toolchain'gcc'(GNUGCC):CouldnotdetermineGCCmetadata:couldnotfindvendorinoutputof/usr/local/gcc-4.9.4/bin/gcc.

-Toolchain'clang'(Clang):CouldnotfindCcompiler'clang'insystempath.

*Try:

Runwith--stacktraceoptiontogetthestacktrace.Runwith--infoor--debugoptiontogetmorelogoutput.Runwith--scantogetfullinsights.

*Getmorehelpathttps://help.gradle.org

BUILDFAILEDin3m47s

~

看起来是gcc或者clang的问题… 先装个clang再说,可能clang太常用了,所以文档没有提到,这下一定可以了。

然而又报错:

Shell

> Task :grpc-compiler:linkJava_pluginExecutable FAILED

/usr/bin/ld: cannot find -lstdc++

clang: error: linker command failed with exit code 1 (use -v to see invocation)

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':grpc-compiler:linkJava_pluginExecutable'.

> A build operation failed.

Linker failed while linking protoc-gen-grpc-java.

See the complete log at: file:///home/renkuanze/github/grpc-java/compiler/build/tmp/linkJava_pluginExecutable/output.txt

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

~

~

~

~

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

>Task:grpc-compiler:linkJava_pluginExecutableFAILED

/usr/bin/ld:cannotfind-lstdc++

clang:error:linkercommandfailedwithexitcode1(use-vtoseeinvocation)

FAILURE:Buildfailedwithanexception.

*Whatwentwrong:

Executionfailedfortask':grpc-compiler:linkJava_pluginExecutable'.

>Abuildoperationfailed.

Linkerfailedwhilelinkingprotoc-gen-grpc-java.

Seethecompletelogat:file:///home/renkuanze/github/grpc-java/compiler/build/tmp/linkJava_pluginExecutable/output.txt

*Try:

Runwith--stacktraceoptiontogetthestacktrace.Runwith--infoor--debugoptiontogetmorelogoutput.Runwith--scantogetfullinsights.

*Getmorehelpathttps://help.gradle.org

~

~

~

~

??????

看起来是stdc++的lib没有找到。

在centos上安装了:libstdc++.x86_64 4.8.5-28.el7_5.1 @updates

libstdc++-devel.x86_64 4.8.5-28.el7_5.1 @updates

libstdc++-static.x86_64

这回一定没问题了吧?

然而继续报错,变成了javedoc找不到

Shell

*** Skipping the build of codegen and compilation of proto files because skipCodegen=true

> Task :grpc-all:javadoc FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':grpc-all:javadoc'.

> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/home/renkuanze/github/grpc-java/all/build/tmp/javadoc/javadoc.options'

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s

30 actionable tasks: 1 executed, 29 up-to-date

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

***SkippingthebuildofcodegenandcompilationofprotofilesbecauseskipCodegen=true

>Task:grpc-all:javadocFAILED

FAILURE:Buildfailedwithanexception.

*Whatwentwrong:

Executionfailedfortask':grpc-all:javadoc'.

>Javadocgenerationfailed.GeneratedJavadocoptionsfile(usefulfortroubleshooting):'/home/renkuanze/github/grpc-java/all/build/tmp/javadoc/javadoc.options'

*Try:

Runwith--stacktraceoptiontogetthestacktrace.Runwith--infoor--debugoptiontogetmorelogoutput.Runwith--scantogetfullinsights.

*Getmorehelpathttps://help.gradle.org

BUILDFAILEDin1s

30actionabletasks:1executed,29up-to-date

简直了。。。grpc的文档还是一如既往的辣鸡。。。目前还在坑里面,先把前面踩的坑记录一下。

然后继续报错:

Shell

*** Skipping the build of codegen and compilation of proto files because skipCodegen=true

> Task :grpc-all:javadoc FAILED

FAILURE: Build failed with an exception.

* What went wrong:

Execution failed for task ':grpc-all:javadoc'.

> Javadoc generation failed. Generated Javadoc options file (useful for troubleshooting): '/home/renkuanze/github/grpc-java/all/build/tmp/javadoc/javadoc.options'

* Try:

Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 3s

30 actionable tasks: 6 executed, 24 up-to-date

~

~

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

***SkippingthebuildofcodegenandcompilationofprotofilesbecauseskipCodegen=true

>Task:grpc-all:javadocFAILED

FAILURE:Buildfailedwithanexception.

*Whatwentwrong:

Executionfailedfortask':grpc-all:javadoc'.

>Javadocgenerationfailed.GeneratedJavadocoptionsfile(usefulfortroubleshooting):'/home/renkuanze/github/grpc-java/all/build/tmp/javadoc/javadoc.options'

*Try:

Runwith--stacktraceoptiontogetthestacktrace.Runwith--infoor--debugoptiontogetmorelogoutput.Runwith--scantogetfullinsights.

*Getmorehelpathttps://help.gradle.org

BUILDFAILEDin3s

30actionabletasks:6executed,24up-to-date

~

~

好像不是很对啊…

文档固然辣鸡,但是会不会有其他打开方式?

于是跑到工程院那边请教了同事…发现果然打开方式不正确…

正确的方式是直接在依赖管理工具如maven中添加,并不需要手动编译安装…

Although hardly a comprehensive list, these are the most common default lifecycle phases executed.

validate: validate the project is correct and all necessary information is available

compile: compile the source code of the project

test: test the compiled source code using a suitable unit testing framework. These tests should not require the code be packaged or deployed

package: take the compiled code and package it in its distributable format, such as a JAR.

integration-test: process and deploy the package if necessary into an environment where integration tests can be run

verify: run any checks to verify the package is valid and meets quality criteria

install: install the package into the local repository, for use as a dependency in other projects locally

deploy: done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects.

There are two other Maven lifecycles of note beyond the default list above. They are

clean: cleans up artifacts created by prior builds

site: generates site documentation for this project

发现mvn package的时候会报几百行的错误

于是先执行mvn validate验证一下情况,

最上面的错误如下:

Java

[INFO] Scanning for projects...

[INFO] ------------------------------------------------------------------------

[INFO] Detecting the operating system and CPU architecture

[INFO] ------------------------------------------------------------------------

[INFO] os.detected.name: osx

[INFO] os.detected.arch: x86_64

[INFO] os.detected.classifier: osx-x86_64

[WARNING] Failed to inject repository session properties.

java.lang.NoSuchMethodError: org.apache.maven.execution.MavenSession.getRepositorySession()Lorg/eclipse/aether/RepositorySystemSession;

at kr.motd.maven.os.RepositorySessionInjector.injectRepositorySession(RepositorySessionInjector.java:22)

at kr.motd.maven.os.DetectExtension.injectSession(DetectExtension.java:148)

at kr.motd.maven.os.DetectExtension.afterProjectsRead(DetectExtension.java:107)

at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:274)

at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)

at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537)

at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)

at org.apache.maven.cli.MavenCli.main(MavenCli.java:141)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)

at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)

at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)

at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

at org.codehaus.classworlds.Launcher.main(Launcher.java:47)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:483)

at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

[INFO]

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

[INFO]Scanningforprojects...

[INFO]------------------------------------------------------------------------

[INFO]DetectingtheoperatingsystemandCPUarchitecture

[INFO]------------------------------------------------------------------------

[INFO]os.detected.name:osx

[INFO]os.detected.arch:x86_64

[INFO]os.detected.classifier:osx-x86_64

[WARNING]Failedtoinjectrepositorysessionproperties.

java.lang.NoSuchMethodError:org.apache.maven.execution.MavenSession.getRepositorySession()Lorg/eclipse/aether/RepositorySystemSession;

atkr.motd.maven.os.RepositorySessionInjector.injectRepositorySession(RepositorySessionInjector.java:22)

atkr.motd.maven.os.DetectExtension.injectSession(DetectExtension.java:148)

atkr.motd.maven.os.DetectExtension.afterProjectsRead(DetectExtension.java:107)

atorg.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:274)

atorg.apache.maven.DefaultMaven.execute(DefaultMaven.java:156)

atorg.apache.maven.cli.MavenCli.execute(MavenCli.java:537)

atorg.apache.maven.cli.MavenCli.doMain(MavenCli.java:196)

atorg.apache.maven.cli.MavenCli.main(MavenCli.java:141)

atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)

atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

atjava.lang.reflect.Method.invoke(Method.java:483)

atorg.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)

atorg.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)

atorg.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409)

atorg.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352)

atorg.codehaus.classworlds.Launcher.main(Launcher.java:47)

atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod)

atsun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

atjava.lang.reflect.Method.invoke(Method.java:483)

atcom.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

[INFO]

下一步该进行mvn compile,也ok

然后是mvn test,又是几百行错误…核心的信息是java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument

添加了两个依赖(再次吐槽grpc-java官方文档&demo的不靠谱)

XHTML

**Please add following dependencies in your project.**

com.google.guava

guava

23.6-jre

org.apache.httpcomponents

httpcore

4.4.8

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

**Pleaseaddfollowingdependenciesinyourproject.**

com.google.guava

guava

23.6-jre

org.apache.httpcomponents

httpcore

4.4.8

似乎是ok了.

然后执行mvn package,继续报错,好在只有几十行…

Shell

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage (default) on project grpc-demo: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage failed: Unable to find a single main class from the following candidates [io.grpc.examples.advanced.HelloJsonClient, io.grpc.examples.advanced.HelloJsonServer, io.grpc.examples.alts.HelloWorldAltsClient, io.grpc.examples.alts.HelloWorldAltsServer, io.grpc.examples.errorhandling.DetailErrorSample, io.grpc.examples.errorhandling.ErrorHandlingClient, io.grpc.examples.experimental.CompressingHelloWorldClient, io.grpc.examples.header.CustomHeaderClient, io.grpc.examples.header.CustomHeaderServer, io.grpc.examples.helloworld.HelloWorldClient, io.grpc.examples.helloworld.HelloWorldServer, io.grpc.examples.helloworldtls.HelloWorldClientTls, io.grpc.examples.helloworldtls.HelloWorldServerTls, io.grpc.examples.manualflowcontrol.ManualFlowControlClient, io.grpc.examples.manualflowcontrol.ManualFlowControlServer, io.grpc.examples.routeguide.RouteGuideClient, io.grpc.examples.routeguide.RouteGuideServer] -> [Help 1]

[ERROR]

[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.

[ERROR] Re-run Maven using the -X switch to enable full debug logging.

[ERROR]

[ERROR] For more information about the errors and possible solutions, please read the following articles:

[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

1

2

3

4

5

6

7

8

9

10

11

12

13

[ERROR]Failedtoexecutegoalorg.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackage(default)onprojectgrpc-demo:Executiondefaultofgoalorg.springframework.boot:spring-boot-maven-plugin:2.0.3.RELEASE:repackagefailed:Unabletofindasinglemainclassfromthefollowingcandidates[io.grpc.examples.advanced.HelloJsonClient,io.grpc.examples.advanced.HelloJsonServer,io.grpc.examples.alts.HelloWorldAltsClient,io.grpc.examples.alts.HelloWorldAltsServer,io.grpc.examples.errorhandling.DetailErrorSample,io.grpc.examples.errorhandling.ErrorHandlingClient,io.grpc.examples.experimental.CompressingHelloWorldClient,io.grpc.examples.header.CustomHeaderClient,io.grpc.examples.header.CustomHeaderServer,io.grpc.examples.helloworld.HelloWorldClient,io.grpc.examples.helloworld.HelloWorldServer,io.grpc.examples.helloworldtls.HelloWorldClientTls,io.grpc.examples.helloworldtls.HelloWorldServerTls,io.grpc.examples.manualflowcontrol.ManualFlowControlClient,io.grpc.examples.manualflowcontrol.ManualFlowControlServer,io.grpc.examples.routeguide.RouteGuideClient,io.grpc.examples.routeguide.RouteGuideServer]->[Help1]

[ERROR]

[ERROR]Toseethefullstacktraceoftheerrors,re-runMavenwiththe-eswitch.

[ERROR]Re-runMavenusingthe-Xswitchtoenablefulldebuglogging.

[ERROR]

[ERROR]Formoreinformationabouttheerrorsandpossiblesolutions,pleasereadthefollowingarticles:

[ERROR][Help1]http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException

摘重点: Unable to find a single main class from the following candidates

看样子是找不到程序入口在哪里了…好像很合理,毕竟grpc-java的example里每个文件都带了main函数

XHTML

profile1

com.SomeClass

profile2

com.SomeOtherClass

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

profile1

com.SomeClass

profile2

com.SomeOtherClass

XHTML

org.springframework.boot

spring-boot-maven-plugin

1.5.2.RELEASE

repackage

${spring.boot.mainclass}

...

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

org.springframework.boot

spring-boot-maven-plugin

1.5.2.RELEASE

repackage

${spring.boot.mainclass}

...

然后另一边,将python的server启动起来

注意ip和端口号要保持一致. ok了

XHTML

java -jar /data/downloads/grpc-demo/target/grpc-demo-0.0.1-SNAPSHOT-exec.jar

十月 18, 2018 11:48:06 上午 io.grpc.examples.helloworld.HelloWorldClient greet

信息: Will try to greet sensetime autobots java backend ...

十月 18, 2018 11:48:06 上午 io.grpc.examples.helloworld.HelloWorldClient greet

信息: Greeting: Hello, sensetime autobots java backend from python server

1

2

3

4

5

6

7

8

9

10

11

java-jar/data/downloads/grpc-demo/target/grpc-demo-0.0.1-SNAPSHOT-exec.jar

十月18,201811:48:06上午io.grpc.examples.helloworld.HelloWorldClientgreet

信息:Willtrytogreetsensetimeautobotsjavabackend...

十月18,201811:48:06上午io.grpc.examples.helloworld.HelloWorldClientgreet

信息:Greeting:Hello,sensetimeautobotsjavabackendfrompythonserver

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值