ANTLR Tool version 4.13.1 used for code generation does not match the current runtime version 4.7.2
当我使用neo4j
过程中,遇到了该问题:
ANTLR Tool version 4.13.1 used for code generation does not match the current runtime version 4.7.2ANTLR Runtime version 4.13.1 used for parser compilation does not match the current runtime version 4.7.2Exception
该问题是因为我使用了neo4j-5.23.0
和 apoc-4.4.0.31-all.jar
, 经过设置当我再重启 neo4j
时遇到的,这会导致neo4j-5.23.0
启动失败,具体信息如下:
Changed password for user 'neo4j'. IMPORTANT: this change will only take effect if performed before the database is started for the first time.
Logging config in use: File '/var/lib/neo4j/conf/user-logs.xml'
INFO Starting...
INFO This instance is ServerId{e3a155a0} (e3a155a0-30e3-4c1a-b886-00fd12321f2b)
ANTLR Tool version 4.13.1 used for code generation does not match the current runtime version 4.7.2ANTLR Runtime version 4.13.1 used for parser compilation does not match the current runtime version 4.7.2Exception in thread "main" java.lang.ExceptionInInitializerError
at org.neo4j.cypher.internal.parser.v5.ast.factory.Cypher5AstParser.newLexer(Cypher5AstParser.scala:50)
at org.neo4j.cypher.internal.parser.ast.AntlrAstParser.preparsedTokens(AntlrAstParser.scala:107)
at org.neo4j.cypher.internal.parser.ast.AntlrAstParser.parse(AntlrAstParser.scala:45)
at org.neo4j.cypher.internal.parser.ast.AntlrAstParser.parse$(AntlrAstParser.scala:43)
at org.neo4j.cypher.internal.parser.v5.ast.factory.Cypher5AstParser.parse(Cypher5AstParser.scala:34)
at org.neo4j.cypher.internal.parser.v5.ast.factory.Cypher5AstParser.expression(Cypher5AstParser.scala:41)
at org.neo4j.cypher.internal.evaluator.SimpleInternalExpressionEvaluator$ExpressionParser$.parse(SimpleInternalExpressionEvaluator.scala:159)
at org.neo4j.cypher.internal.evaluator.SimpleInternalExpressionEvaluator.$anonfun$evaluate$1(SimpleInternalExpressionEvaluator.scala:70)
at org.neo4j.cypher.internal.evaluator.SimpleInternalExpressionEvaluator.errorContext(SimpleInternalExpressionEvaluator.scala:83)
at org.neo4j.cypher.internal.evaluator.SimpleInternalExpressionEvaluator.evaluate(SimpleInternalExpressionEvaluator.scala:69)
at org.neo4j.cypher.internal.evaluator.SimpleExpressionEvaluator.evaluate(SimpleExpressionEvaluator.java:43)
at org.neo4j.procedure.impl.MapConverter.apply(MapConverter.java:41)
at org.neo4j.procedure.impl.MapConverter.apply(MapConverter.java:30)
at org.neo4j.procedure.impl.TypeCheckers$DefaultValueConverter.defaultValue(TypeCheckers.java:282)
at org.neo4j.procedure.impl.MethodSignatureCompiler.signatureFor(MethodSignatureCompiler.java:83)
at org.neo4j.procedure.impl.ProcedureCompiler.compileProcedure(ProcedureCompiler.java:272)
at org.neo4j.procedure.impl.ProcedureCompiler.compileProcedure(ProcedureCompiler.java:243)
at org.neo4j.procedure.impl.ProcedureCompiler.compileProcedure(ProcedureCompiler.java:358)
at org.neo4j.procedure.impl.GlobalProceduresRegistry$BulkRegistration.registerProcedure(GlobalProceduresRegistry.java:320)
at org.neo4j.graphdb.factory.module.edition.AbstractEditionModule.registerProcedures(AbstractEditionModule.java:96)
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.lambda$setupProcedures$7(DatabaseManagementServiceFactory.java:404)
at org.neo4j.graphdb.factory.module.edition.AbstractEditionModule.tryResolveOrCreate(AbstractEditionModule.java:221)
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.setupProcedures(DatabaseManagementServiceFactory.java:414)
at org.neo4j.graphdb.facade.DatabaseManagementServiceFactory.build(DatabaseManagementServiceFactory.java:177)
at org.neo4j.server.CommunityBootstrapper.createNeo(CommunityBootstrapper.java:38)
at org.neo4j.server.NeoBootstrapper.start(NeoBootstrapper.java:184)
at org.neo4j.server.NeoBootstrapper.start(NeoBootstrapper.java:99)
at org.neo4j.server.CommunityEntryPoint.main(CommunityEntryPoint.java:30)
Caused by: java.lang.UnsupportedOperationException: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3).
at org.antlr.v4.runtime.atn.ATNDeserializer.deserialize(ATNDeserializer.java:187)
at org.neo4j.cypher.internal.parser.v5.Cypher5Lexer.<clinit>(Cypher5Lexer.java:3154)
... 28 more
Caused by: java.io.InvalidClassException: org.antlr.v4.runtime.atn.ATN; Could not deserialize ATN with version 4 (expected 3).
... 30 more
INFO Neo4j Server shutdown initiated by request
INFO Stopped.
这个问题的解答在2. 使用适合版本neo4j
安装AOPC
插件.
在说这个问题的解答之前,我先说一下更前面的一个问题.
ValueError: Could not use APOC procedures. Please ensure the APOC plugin is installed in Neo4j and that 'apoc.meta.data()' is allowed in Neo4j configuration
1. 在neo4j
上安装APOC
插件
**ValueError**: Could not use APOC procedures. Please ensure the APOC plugin is installed in Neo4j and that 'apoc.meta.data()' is allowed in Neo4j configuration
刚才这个错误提示我们需要在Neo4j
上安装APOC (Awesome Procedures On Cypher)
程序.
因为我们已经通过docker
启用了neo4j-523
容器,于是接下来需要将APOC
作为插件安装到neo4j-5.23.0
对应版本的容器即可.
1.1 下载并安装APOC
插件
从 Neo4j APOC GitHub repository 上下载最新版本的apoc-4.4.0.31-all.jar
,并将其放置到neo4j
的 plugins
目录下.
1.2 配置并启用APOC
程序
我们只需执行两步, 第一步编辑 conf/neo4j.conf
文件填入下面两行配置:
-
dbms.security.procedures.unrestricted=apoc.* dbms.security.procedures.allowlist=apoc.meta.data
-
重启 Neo4j:
docker restart neo4j-523
通过这些步骤,我们确实可以消除 ValueError
并且正确启动 Neo4jGraph
类.不过,我们又遇到了最开始的问题.
2. 使用适合版本neo4j
安装AOPC
插件
ANTLR Tool version 4.13.1 used for code generation does not match the current runtime version 4.7.2ANTLR Runtime version 4.13.1 used for parser compilation does not match the current runtime version 4.7.2Exception
仔细分析不难得知这是一个版本冲突问题,要解决这个问题,还得从版本上着手.幸运的是,仔细阅读 AOPC
官方文档,我们可以找到一个对应版本关系:
这是 neo4j-apoc-procedures
所支持的对应版本关系表:
apoc version | neo4j version |
---|---|
4.4.0.1 | 4.4.0 (4.3.x) |
4.3.0.4 | 4.3.7 (4.3.x) |
4.2.0.9 | 4.2.11 (4.2.x) |
4.1.0.10 | 4.1.11 (4.1.x) |
4.0.0.18 | 4.0.12 (4.0.x) |
3.5.0.15 | 3.5.30 (3.5.x) |
3.4.0.8 | 3.4.18 (3.4.x) |
3.3.0.4 | 3.3.9 (3.3.x) |
3.2.3.6 | 3.2.14 (3.2.x) |
3.1.3.9 | 3.1.9 (3.1.x) |
3.0.8.6 | 3.0.12 (3.0.x) |
3.5.0.0 | 3.5.0-beta01 |
3.4.0.2 | 3.4.5 |
3.3.0.3 | 3.3.5 |
3.2.3.5 | 3.2.3 |
3.1.3.8 | 3.1.5 |
根据该表,我们可以使用4.4.0
版本的neo4j
以及下载对应的APOC
程序文件apoc-4.4.0.1-all.jar
.
2.1 安装4.4.0
版本neo4j
-
我们先下载对应镜像, 这里我们下载
4.4
社区版.docker pull neo4j:4.4-community
-
创建并启动镜像:
docker run -d \ --name=neo4j-44 \ --publish=7474:7474 --publish=7687:7687 \ --env NEO4J_AUTH=neo4j/neo4j123 \ --volume=/home/lunyu/neo4j/data:/data \ neo4j:4.4-community
这时名为neo4j-44
的容器已启动.
2.2 下载并安装APOC
插件
我们将4.4.0.1版本的APOC
插件下载下来,并将其放置到neo4j
的 plugins
目录下.
2.3 配置并启用APOC
程序
我们只需执行两步, 第一步编辑 conf/neo4j.conf
文件填入下面两行配置:
-
dbms.security.procedures.unrestricted=apoc.* dbms.security.procedures.allowlist=apoc.meta.data
-
重启 Neo4j:
docker restart neo4j-44
经过这些步骤,ANTLR
工具版本冲突问题得以解决。