尝试运行节点时 Corda 示例失败

Corda samples fail when trying to runnodes

我读过但我的环境不同

我已经克隆了 Corda 样本并确保我有 Java 8(更新 301)和 Gradle 5.6.4:

cordapp-example % java -version              
java version "1.8.0_301"
Java(TM) SE Runtime Environment (build 1.8.0_301-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.301-b09, mixed mode)

cordapp-example % gradle -version

------------------------------------------------------------
Gradle 5.6.4
------------------------------------------------------------

Build time:   2019-11-01 20:42:00 UTC
Revision:     dd870424f9bd8e195d614dc14bb140f43c22da98

Kotlin:       1.3.41
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.14 compiled on March 12 2019
JVM:          1.8.0_301 (Oracle Corporation 25.301-b09)
OS:           Mac OS X 10.16 x86_64

然而,当我遵循“运行 示例 Cordapp”时 tutorial 我在 runnodes 步骤失败了:

cordapp-example % bash -c 'cd "/Users/arinea/Munca/Corda/samples-java/Basic/cordapp-example/build/nodes/PartyB" ; "/Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home/bin/java" "-Dcapsule.jvm.args=-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5007 -javaagent:drivers/jolokia-jvm-1.6.0-agent.jar=port=7007,logHandlerClass=net.corda.node.JolokiaSlf4jAdapter" "-Dname=PartyB" "-jar" "/Users/arinea/Munca/Corda/samples-java/Basic/cordapp-example/build/nodes/PartyB/corda.jar" && exit'
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by Capsule (file:/Users/arinea/Munca/Corda/samples-java/Basic/cordapp-example/build/nodes/PartyB/corda.jar) to field com.sun.jmx.mbeanserver.JmxMBeanServer.mbsInterceptor
WARNING: Please consider reporting this to the maintainers of Capsule
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Listening for transport dt_socket at address: 5007
[quasar] ERROR: java/lang/Object
java.lang.IllegalArgumentException
at co.paralleluniverse.asm.ClassReader.<init>(Unknown Source)
at co.paralleluniverse.asm.ClassReader.<init>(Unknown Source)
at co.paralleluniverse.asm.ClassReader.<init>(Unknown Source)
at co.paralleluniverse.fibers.instrument.MethodDatabase.checkFileAndClose(MethodDatabase.java:345)
at co.paralleluniverse.fibers.instrument.MethodDatabase.checkClass(MethodDatabase.java:325)
at co.paralleluniverse.fibers.instrument.MethodDatabase.getOrLoadClassEntry(MethodDatabase.java:184)
at co.paralleluniverse.fibers.instrument.SimpleSuspendableClassifier.isSuspendable(SimpleSuspendableClassifier.java:156)
at co.paralleluniverse.fibers.instrument.DefaultSuspendableClassifier.isSuspendable(DefaultSuspendableClassifier.java:47)
at co.paralleluniverse.fibers.instrument.CheckInstrumentationVisitor.visitMethod(CheckInstrumentationVisitor.java:130)
at co.paralleluniverse.asm.ClassReader.b(Unknown Source)
at co.paralleluniverse.asm.ClassReader.accept(Unknown Source)
at co.paralleluniverse.asm.ClassReader.accept(Unknown Source)
at co.paralleluniverse.fibers.instrument.MethodDatabase.checkFileAndClose(MethodDatabase.java:348)
at co.paralleluniverse.fibers.instrument.MethodDatabase.checkClass(MethodDatabase.java:325)
at co.paralleluniverse.fibers.instrument.MethodDatabase.getOrLoadClassEntry(MethodDatabase.java:184)
at co.paralleluniverse.fibers.instrument.MethodDatabase.isMethodSuspendable0(MethodDatabase.java:195)
at co.paralleluniverse.fibers.instrument.MethodDatabase.isMethodSuspendable(MethodDatabase.java:162)
at co.paralleluniverse.fibers.instrument.InstrumentMethod.isSuspendableCall(InstrumentMethod.java:231)
at co.paralleluniverse.fibers.instrument.LabelSuspendableCallSitesClassVisitor.visitMethodInsn(LabelSuspendableCallSitesClassVisitor.java:64)
at co.paralleluniverse.asm.ClassReader.a(Unknown Source)
at co.paralleluniverse.asm.ClassReader.b(Unknown Source)
at co.paralleluniverse.asm.ClassReader.accept(Unknown Source)
at co.paralleluniverse.asm.ClassReader.accept(Unknown Source)
at co.paralleluniverse.fibers.instrument.QuasarInstrumentor.instrumentClass(QuasarInstrumentor.java:129)
at co.paralleluniverse.fibers.instrument.QuasarInstrumentor.instrumentClass(QuasarInstrumentor.java:100)
at co.paralleluniverse.fibers.instrument.JavaAgent$Transformer.transform(JavaAgent.java:241)
at java.instrument/java.lang.instrument.ClassFileTransformer.transform(ClassFileTransformer.java:246)
at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:563)
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:398)
at java.base/sun.launcher.LauncherHelper.loadMainClass(LauncherHelper.java:760)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:655)

仔细检查失败的三个选项卡中的第一行,我们看到:

... "/Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home/bin/java" ...

我的 OS X 上也安装了这个 Java 11,但为什么它被拾取了!? java -version,如上所示,指向1.8 u301,

cordapp-example % echo $JAVA_HOME
/Users/arinea/.jenv/versions/1.8.0.301

cordapp-example % ll /Users/arinea/.jenv/versions
total 0
lrwxr-xr-x  1 arinea  staff    64B 24 Iul 22:37 1.8 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    64B 24 Iul 22:37 1.8.0.241 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    64B 13 Aug 16:00 1.8.0.301 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    63B 24 Iul 22:37 11 -> /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    63B 24 Iul 22:37 11.0 -> /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    63B 24 Iul 22:37 11.0.10 -> /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    64B 24 Iul 22:37 oracle64-1.8.0.241 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_241.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    64B 13 Aug 16:00 oracle64-1.8.0.301 -> /Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
lrwxr-xr-x  1 arinea  staff    63B 24 Iul 22:37 oracle64-11.0.10 -> /Library/Java/JavaVirtualMachines/jdk-11.0.10.jdk/Contents/Home

我这辈子都不知道为什么 JDK11 被选中了。我需要将它从我的系统中删除吗?


稍后编辑:

当我从 cordapp-example 目录中 运行 ./build/nodes/runnodes 时,就会出现这个问题。如果我去 build/nodes 和 运行 那里 java -jar runnodes.jar 一切正常,正如预期的那样...

答案就在runnodes脚本文件中:

 1  #!/usr/bin/env bash
 2  
 3  set -eo pipefail
 4  
 5  # Allow the script to be run from outside the nodes directory.
 6  basedir=$( dirname "[=10=]" )
 7  cd "$basedir"
 8  
 9  if [ -z "$JAVA_HOME" ] && which osascript >/dev/null; then
10      # use default version of java installed on mac
11      /usr/libexec/java_home --exec java -jar runnodes.jar "$@"
12  else
13      "${JAVA_HOME:+$JAVA_HOME/bin/}java" -jar runnodes.jar "$@"
14  fi

第 11 行(与第 13 行相反)执行,它使用 /usr/libexec/java_home 在我的情况下(以及许多其他人的情况,根据我在网上找到的内容判断......)将指向最新的JDK 已安装。那是 JDK 11 而 Corda 不兼容它。

只要确保你不使用那个,而是使用 JDK 8 以上更新 131。