ANTLR4 TestRig(grun)引发java.lang.NoClassDefFoundError异常

编程入门 行业动态 更新时间:2024-10-19 06:25:41
本文介绍了ANTLR4 TestRig(grun)引发java.lang.NoClassDefFoundError异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试学习ANTLR 4,并且正在遵循权威ANTLR 4参考中给出的示例.可悲的是,我陷入了第一个例子.

I'm trying to learn ANTLR 4, and I'm following the examples given in The Definitive ANTLR 4 Reference. Sadly I'm stuck at the first example.

系统:Windows 10(1703)Java 8,更新151 ANTLR 4,v4.7

System: Windows 10 (1703) Java 8, update 151 ANTLR 4, v4.7

我的%CLASSPATH%设置为系统变量( .;"D:\ Program Files \ Java \ libs \ antlr-4.7-complete.jar"; ).我的%PATH%中有 antlr4.bat 和 grun.bat ,并且能够运行 antlr4 .

My %CLASSPATH% is set as a system variable (.;"D:\Program Files\Java\libs\antlr-4.7-complete.jar";). I have antlr4.bat and grun.bat available in my %PATH%, and I'm able to run antlr4 from the command line.

antlr4.bat : java -cp%CLASSPATH%org.antlr.v4.Tool%* grun.bat : java -cp%CLASSPATH%org.antlr.v4.gui.TestRig%*

我之所以明确使用 -cp%CLASSPATH%是因为我看到其他一些人在不使用 -cp 选项时遇到了问题.

I'm using -cp %CLASSPATH% explicitly because I've seen a few others having problems when not using the -cp option.

我的问题是这样的:当我在示例语法 Hello ( grun Hello r -tokens )上运行 grun 时,我收到此错误消息

My problem is this: When I run grun on the example grammar Hello (grun Hello r -tokens) I get this error message

Exception in thread "main" java.lang.NoClassDefFoundError: HelloLexer (wrong name: main/resource/hello/HelloLexer) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(Unknown Source) at java.security.SecureClassLoader.defineClass(Unknown Source) at java.URLClassLoader.defineClass(Unknown Source) at java.URLClassLoader.access$100(Unknown Source) at java.URLClassLoader$1.run(Unknown Source) at java.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at org.antlr.v4.gui.TestRig.process(TestRig.java:129) at org.antlr.v4.gui.TestRig.main(TestRig.java:119)

对我在做什么错有任何想法吗?提前非常感谢!

Any ideas to what I'm doing wrong? Many thanks in advance!

我以为我找到了答案.通过 cd -进入编译文件所在的文件夹(而不是从根项目文件夹中调用 grun ),我设法了解了有问题的示例.

I thought I had found an answer. By cd-ing into the folder where the compiled files were (instead of calling grun from the root project folder) I managed to get through the example in question.

但是当我尝试建立自己的项目时,遇到了相同的问题,并带有与上面相同的错误消息.

But when I tried to set up my own project, I came across the same issue, with the same error message as above.

这一次,当我使用 -package 选项运行 antlr4 后,似乎 grun 抱怨了.

This time, it seems like grun is complaining after I've run antlr4 with the -package option.

有人知道这是为什么吗?

Does anyone know why this is?

推荐答案

哇...该解决方案当然是一个简单的解决方案...我的问题是我有 cd 转到测试项目的根文件夹,然后只需要 cd 到编译文件所在的目录(并从其中调用 grun )即可.

Wow... The solution was, of course, an easy solution... My problem was that I had cd'd to the root folder of my test project, and I just had to cd to (and call grun from) the directory where the compiled files are.

看来我仍然对 grun 有问题.请参阅已编辑的问题.

It seems like I still have an issue with grun. See edited question.

Edit2:据我所知, grun 与 antlr4 的 -package 选项配合不佳.因此,我的解决方案是必须将我的项目设置为Gradle项目,因为显然效果更好.

From what I can tell, grun doesn't cooperate very well with antlr4's -package option. So my solution was that I had to set up my project as a Gradle project, because apparently that works better.

更多推荐

ANTLR4 TestRig(grun)引发java.lang.NoClassDefFoundError异常

本文发布于:2023-11-25 23:51:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1631835.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:异常   grun   TestRig   NoClassDefFoundError   lang

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!