ANTLR Warning: TestRig moved to org.antlr.v4.gui.TestRig - java

I have been trying to get ANTLR to work all day. I have used several websites including antlr.org, numerous StackOverflow queries and the textbook by Terence Parr. I am on a Windows 7 machine (work machine, can't change to Linux) but I have tried this on both CommandPrompt and Cygwin, with the same result.
No matter what I do, when it comes time to use the grun file, I always come up with the same error in the end:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Hello as lexer or parser
I have the most recent versions of the JRE and JDK on my computer, as well as the most recent version of cygwin.
I can run the batch files for grun and antlr4 from anywhere, so I'm strongly guessing my path is set correctly. I can run antlr4.bat with absolutely no issue. It creates every file the text book says I should see:
Hello.g4 HelloBaseListener.java HelloLexer.tokens HelloParser.java Hello.tokens HelloLexer.java HelloListener.java
I can run javac on those files and it generates various CLASS files:
HelloBaseListener.class HelloLexer.class HelloListener.class HelloParser$RContext.class HelloParser.class
But then, when I try to run grun on it, I get this:
Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically
Can't load Hello as lexer or parser
I've tried several combinations of commands to use the grun file, but the one it says to use in the book is:
grun.bat Hello r -tree
I've also changed the .bat file with grun several times, just to experiment, using different combinations in the books and on the sites, but I always come back to this:
java org.antlr.v4.runtime.misc.TestRig %*
That is what my boss told me to use, and it works for him.

Use this in your grun.bat command
java org.antlr.v4.gui.TestRig %*

I had the same problem, there is actually already a thread with the solution here --> antlr4-Can't load Hello as lexer or parser
The first part of the message "Warning: TestRig moved to org.antlr.v4.gui.TestRig; calling automatically" just means that the TestRig order is saved to another location, it works anyway but I changed my batch data accordingly and did not get the Warning anymore. The second part of the message is the actual problem (see link). In my case I forgot the "." (dot) in my CLASSPATH in Windows.

Related

Can I use -cp argument twice when executing Java?

I am trying to run a Java application which has many dependencies. In the past I have use the following command to launch the application
java -cp "program.jar:jar1.jar:jar2.jar:jar3.jar:[...]" program
However as the list of dependencies have grown, I have moved them into an arguments file, the contents of this file are:
-cp "\
program.jar:\
jar1.jar:\
jar2.jar:\
jar3.jar:\
[...]"
And I am running the application with
java #arguments-file program
Everything up to this point works fine.
Sometimes I end up with beta versions of program.jar, they share all of the same dependencies, but program.jar is renamed program-beta.jar.
So to run the jar the following command would be used
java -cp "program-beta.jar:jar1.jar:jar2.jar:jar3.jar:[...]" program
or more specifically, I would use an environment variable, so that the same script can be used, and the variable would be set to either program.jar, or program-beta.jar, depending on the circumstance
java -cp "$PROGRAM_JAR:jar1.jar:jar2.jar:jar3.jar:[...]" program
Now that I am using an arguments file I was hoping to be able to be able to do something like:
java -cp "$PROGRAM_JAR" #arguments-file program
However using -cp twice causes one of the two to be ignored, resulting in a java.lang.ClassNotFoundException exception.
Is there any way around this that allows me to specify one jar file by name, but abstract away all of the others so that my java command isn't thousands of characters?
This will be running entirely on Linux, so any command line "magic", such as using grep is fine, so long as the resulting code is easily readable
You could just write two bash scripts production.sh and beta.sh that contain a reference on program.jar and program-beta.jar, respectively.
Also, the classpath can contain wildcards (see man-page), so if you can ensure that on disk exists only one of the two versions, you can write it like this:
java -cp "program*:jar1.jar:jar2.jar:jar3.jar:[...]"
In the long term, you might think about building/running it with Maven or Gradle, depending on your requirements.

Old OpenGL/Gluegen and basic errors on 32-bit Java. Migration or rookie mistake?

As a total noob in Java faced with the task of making this program work asap, unfortunately I'm stuck on a loop after consuming the basic bibliography.
The scenario is a 32-bit Linux machine (Ubuntu 16), which has installed both OpenJDK 8 and 11.
And a Java Software where tree . yields
- shiftone-jrat.jar // <-- Special jar because it's outside "lib"?
- fooModule
- foo.class
- foo.java
- ...
- barModule
- bar.class
- bar.java
- ...
- ui
- Main.class
- Main.java // <-- Special Code because it has "main()"
- ...
- lib
- jogl.jar
- vecmath.jar
- gluegen-rt.jar
- ...
- run.bat
- .classpath
The presence of run.bat files suggest that it was compiled in Windows, and after opening .classpath one can note the process was managed from the Eclipse IDE.
As far as I understand Java is very portable so there is no need to recompile the files, we only need to run it.
The only command that has worked without errors is
java -jar shiftone-jrat.jar
But after a quick Google search one can note that jrat is only a profiler.
Thus, the relevant call has to be
java ui.Main
Nevertheless, that yields noClassDefFoundError: the first thing it can complain about before termination is a package called 'vecmath' which is part of our jars in ./lib. Therefore the option cp is added to the command java, like this
java -cp "lib/*" ui.Main"
In this case the problem is that ui.Main itself is not found, so the option is passed a new argument like this:
java -cp ".:lib/*" ui.Main"
Up to this point the previous questions on the same topic here on StackOverflow are very informative. For this particular case they are not sufficient, as the previous command opens a (blank) window that reports the following error:
no gluegen-rt in java.library.path
Where java.library.path includes common root places (e.g. /usr/lib/jni, /usr/lib, /lib and /usr/java/packages/lib).
Please note that there is a .jar called gluegen-rt.jar at ./lib, the same folder that made the previous error vanish by providing a jar called vecmath.jar.
Without fully understanding what .jars are, I downloaded libgluegen2 (and perhaps also jogamp,or it is included? sorry, I don't remember) from ubuntu apt.pkgs (which is the only one I've found, i.e. the "2"), and replaced the
lib/gluegen-rt.jar file with the jar from
/usr/share/java/gluegen2-2.3.2-rt.jar.
Again, I ran
java -cp ".:lib/*" ui.Main"
And now the NoClassDefFoundError mentions gluegen/runtime/DynamicLookupHelper.
A quick (cd /usr/share/java ; grep -r "DynamicLookupHelper") shows that jogl2.jar also matches and thus I also overwrite
lib/jogl.jar file with the jar from
/usr/share/java/jogl2.jar.
Finally the NoClassDefFoundError error is thrown again, this time because there is no such thing as javax.media.opengl, which is often used in the program java's files at imports.
A quick Google search yields that Java's implementation of OpenGL had "some" changes at "some" point in time, thus the lines
javax.media.opengl should be changed to
com.jogamp.opengl to comply with our "newest" version.
I made the changes but then some other lines were broken, so finally I appear to be faced with either (1) looking for the "right" jogamp and/or gluegen or (2) continue the migration. There may be 5k lines.
Questions such as: Is there any other option I'm missing? Is the whole procedure correct? Where are old versions available? Can I leverage the xml-styled .classpath file?
Thanks

How can I run multiple threads in JOMP on Windows (10) from either the command prompt or in Eclipse?

I can't get multiple threads to run using JOMP no matter what I try. I actually can't run a JOMP program from the command line no matter what I try either in fact, although ironically it will compile from there and then run in Eclipse! Even in Eclipse though I only have one thread. I've been through the notes from my university course about installation of JOMP carefully, but they have not helped. I'll be more specific though:
Items in quotes below are from those notes:
"There are a couple of websites that tell you how to make jomp run under Eclipse, see http://www.lst.inf.ethz.ch/teaching/lectures/ss10/24/ assignments/assignment_10/eclipse.txt"
This refers to a now broken link. It also seem to be the only link anyone on forums like Stackoverflow refer to when talking about this issue. Apparently it has instructions on runtime settings for Eclipse to allow multiple threads to run, but since the link is currently broken I can't access those valuable instructions.
"All that is required in order to do that is to ensure that jomp1.0b.jar is on the CLASSPATH"
I ran echo %CLASSPATH% at the command prompt to check if it was on the class path and got the following response:
C:\Program Files\Java\jre1.8.0_162\lib\jomp1.0b.jar
On my PC the jomp jar file is in that folder, so it appears I should be able to execute compiled JOMP programs from the command line, but unfortunately that is not the case. By executing one of these commands it should run:
java −Djomp.threads=2 parallel
java −Djomp.threads=2 -cp . parallel
java −Djomp.threads=2 -cp C:\Users\terry\eclipse-workspace\JOMPHello\src parallel
This is the folder the jomp, java and compiled class files are in. I also checked if "parallel" is the fully qualified class name in the way I have set it up in Eclipse, and it does appears to be. So running one of these commands should allow me to run the jomp program from the command line as near as I can tell, but they all return the following error:
Error: Could not find or load main class parallel
Caused by: java.lang.ClassNotFoundException: parallel
(To which I feel like telling Java, "You're not looking hard it enough! It is right in the folder I am running this command from!")
Clearly I am missing something. Can anyone tell me how to get JOMP programs running on the command line, or alternatively knows where there are accessible instructions for how to set up the work around runtime settings in Eclipse?
My implementation of the program seems to run with only one thread, so hopefully that means it is correct, but I can only be sure once I have run it with at least a few more threads.
Thanks,
Terry.
I figured out how to set up the runtime argument in Eclipse. You just have to add the following line into the VM Arguments box in under the Argument tab in Run Configurations for the file:
−Djomp.threads=n
(where n as before is the number of threads you want).
I'd still like to know why it's not working on the Command Line though. It makes me think my Java is set up weirdly.

Number and type of slashes in path in command prompt

This is kind of a ridiculous question but I am stucked with it and I need some help.
I am trying to install an open source software in my windows 8 system using command prompt. Everything is set correctly but when I type the final java command, to run the software, I get a series of exceptions.
I am sure that the problem is related with some slashes in the path. I know that the type and number of slashes is important and sometimes java requires this.
So I am not sure if I can get an answer about such a specific question here but I give it a try. This is the path I run in one line:
C:\Kuwaiba7\service>java -Djava.rmi.server.codebase="file:/C:/Kuwaiba7/service/lib/PersistenceAbstractionAPI.jar file:/C:/Kuwaiba7/Service/lib/PersistenceServiceRemoteInterfaces.jar" -jar PersistenceService.jar
I double/tripled checked the paths and tried different variations with the slashes but nothing gives me the expected result.
I get the following exceptions:
java.rmi.serverException
java.rmi.unmarshalException
java.lang.classNotFoundException
This is the format of the path they suggest in their manual but doesn't seem to work either:
Thanks
Dimitris
I found the solution and I post the answer here. Afterall the slashes were correct the way I had them. Although sometimes in Java the number and the type of the slashes counts that wasn't the case here.
What I did before was that I was starting the rmiregistry and then running the PersistenceService. That didn't work.
Then I tried to set the Classpath (from the directory where the PersistenceService.jar is located in my PC). After start the rmiregistry.exe (from the Java directory) and finally run the persistence service as shown above.
That made it work!

Javac can't find .class files, have right classpath

Although I'm not new to programming in general, I am new to java, and it seems to work a little bit differently. When trying to compile a .java with javac it gives me this error: cannot find symbol. I looked the cause of this up, and the error occurs when the .class file that you are referencing could not be found. I ensured that all of my references were spelled correctly, I ensured I had the right classpath, I tried compiling a .java file I know is valid, even on an XP computer just in case my Vista installation was the cause, but to no avail. Here are the contents of the .bat I am using to run javac, it could be the cause of my problems.
#echo off
"C:\Program Files (x86)\Java\jdk1.6.0_21\bin\javac" -encoding UTF8 -cp . hl.java
pause
Thank you for the help, this has been troubling me for quite some time now.
Can you show us this?
I tried compiling a .java file I know is valid
Could it be that you are using classes not compiled on . ? Unless your code is as simple as hello world, I'd say chances are high.
This is a long shot, but looking at your script and the error message you described, you're probably not running javac at all. Try this on the command line and see what it says:
C:\Program Files (x86)\Java\jdk1.6.0_21\bin\javac -version
If that doesn't work, then you're not pointing to a valid javac.

Categories