Java cannot find a class in a .jar file

I’ve installed a Java package called Antlr as /usr/local/java/Antlr/antlr-4.1-complete.jar. The installation instructions say to set up two aliases, one to execute the Antlr tool:

alias antlr=‘java -jar /usr/local/java/Antlr/antlr-4.1-complete.jar’

and another to execute the Antlr test tool:

alias grun=‘java org.antlr.v4.runtime.misc.TestRig’

The first alias works fine, but the second, which attempts to invoke a class inside the .jar file, fails with the message, “Error: Could not find or load main class org.antlr.v4.runtime.misc.TestRig”.

Looking at the Java documentation, I see that a CLASSPATH environment variable is available to handle path issues:

"-classpath classpath

-cp classpath
Specify a list of directories, JAR archives, and ZIP archives to
search for class files. Class path entries are separated by
colons (:). Specifying -classpath or -cp overrides any setting of
the CLASSPATH environment variable."

My CLASSPATH variable was unset. I tried

export CLASSPATH=/usr/local/java:/usr/share/java

export CLASSPATH=/usr/local/java:/usr/share/java:/usr/share/java/Antlr/antlr-4.1-complete.jar

and

export CLASSPATH=/usr/local/java:/usr/share/java/:/usr/share/java/

but this has not resolved the problem.

What am I doing wrong?

Leslie

jlturriff wrote:
>
> I’ve installed a Java package called Antlr as
> /usr/local/java/Antlr/antlr-4.1-complete.jar. The installation
> instructions say to set up two aliases, one to execute the Antlr tool:
>
> alias antlr=‘java -jar /usr/local/java/Antlr/antlr-4.1-complete.jar’
>
> and another to execute the Antlr test tool:
>
> alias grun=‘java org.antlr.v4.runtime.misc.TestRig’
>
> The first alias works fine, but the second, which attempts to invoke a
> class inside the .jar file, fails with the message, “Error: Could not
> find or load main class org.antlr.v4.runtime.misc.TestRig”.
>
> Looking at the Java documentation, I see that a CLASSPATH environment
> variable is available to handle path issues:
>
> “-classpath classpath
>
> -cp classpath
> Specify a list of directories, JAR archives, and ZIP archives to
> search for class files. Class path entries are separated by
> colons (:). Specifying -classpath or -cp overrides any setting of
> the CLASSPATH environment variable.”
>
> My CLASSPATH variable was unset. I tried
>
> export CLASSPATH=/usr/local/java:/usr/share/java
>
> export
> CLASSPATH=/usr/local/java:/usr/share/java:/usr/share/java/Antlr/antlr-4.1-complete.jar
>
> and
>
> export CLASSPATH=/usr/local/java:/usr/share/java/:/usr/share/java/
>
> but this has not resolved the problem.
>
> What am I doing wrong?
>
> Leslie
>
>
I a able to run the example from this page
http://www.antlr.org/wiki/display/ANTLR4/Getting+Started+with+ANTLR+v4

Proof :- http://paste.opensuse.org/images/76971458.png

Only thing i did differently was


wget http://antlr4.org/download/antlr-4.1-complete.jar
export
CLASSPATH=".:/home/<userName>/Downloads/antlr-4.1-complete.jar:$CLASSPATH"
antlr4='java -jar /home/<userName>/Downloads/antlr-4.1-complete.jar'
alias grun='java org.antlr.v4.runtime.misc.TestRig'

Ensure that you have java-1_7_0-sun-devel installed using link
http://software.opensuse.org/ymp/Java:sun:Factory/openSUSE_Factory/java-1_7_0-sun-devel.ymp?base=openSUSE%3AFactory&query=java-1_7_0-sun-devel


GNOME 3.6.2
openSUSE Release 12.3 (Dartmouth) 64-bit
Kernel Linux 3.7.10-1.16-desktop