我正在尝试学习Ubuntu上的JFlex和Cup工具,因为我必须在学校的项目中使用它们。所以我下载并安装了JFlex和Cup。"jflex-1.6.1/ examples“中有一些示例,所以我尝试运行其中的一个。特别是,我尝试按照自述文件中的说明运行"jflex-1.6.1/examples/cup“中的命令:
要编译:
jflex lcalc.flex
java java_cup.Main < ycalc.cup
javac Main.java要运行:
java Main test.txt文件:
"Main.java" demo of a main program
"Makefile " makefile to compile and test the example
"README"
"lcalc.flex" the lexer spec
"output.good " how the output should look like for the test
"ycalc.cup" the parser spec
"test.txt " sample input for testing在许多困难的情况下,我终于能够编译,然后成功地完成了前三条指令。现在,当我尝试运行java Main test.txt时,出现了错误。特别是,我得到了这个错误:
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.NoClassDefFoundError: java_cup/runtime/Scanner
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
at java.lang.Class.getMethod0(Class.java:3018)
at java.lang.Class.getMethod(Class.java:1784)
at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)
Caused by: java.lang.ClassNotFoundException: java_cup.runtime.Scanner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more我不知道如何解决这个问题。我也尝试了其他例子,但结果都是一样的。我希望你能帮助我。谢谢!
发布于 2017-12-21 01:34:18
我也得到了这个错误,这是因为我忘记在我的类路径中包括java-cup.jar和java-cup-runtime.jar。
尝试像这样编译:
javac -cp path/to/java-cup.jar Main.java
然后像这样运行你的程序:
java -cp path/to/java-cup-runtime.jar Main
https://stackoverflow.com/questions/47006543
复制相似问题