سؤال

I have an antlr grammar and I have written and listener for it. I am running the latest version of ubuntu.

I run the following commands

#Generate 
java -jar antlr-4.1-complete.jar -package pascal -o pascal pascal.g4
#Compile
javac -cp antlr-4.1-complete.jar pascal/*.java
#Run
java -cp antlr-4.1-complete.jar pascal.pascal sample1.pascal

Everything seems to go fine until the final run command. I get this : https://www.dropbox.com/sh/8majts6voe7c8v9/AADf5GmB3vpbURrp4ONlqSW-a

When I try to do the Run command I get "Error: Could not find or load main class pascal.pascal

I have tried to change pascal.pascal to pascal/pascal.

I have Java "1.7.0_55" installed.

I really do not understand why this does not work as the files with the same commands run on my friends mac.

I do not need help with the actual work, just as to why I keep getting this Error. If you have any ideas it would be appreciated

هل كانت مفيدة؟

المحلول

You didn't add the pascal package to the classpath.

From Mac OS X and Linux do:

java -cp .:antlr-4.4-complete.jar pascal.pascal sample1.pascal

and from Windows:

java -cp .;antlr-4.4-complete.jar pascal.pascal sample1.pascal

Also have a look at Java's code conventions: class names should start with an upper case.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top