Quantcast
Channel: openSUSE Forums
Viewing all articles
Browse latest Browse all 40713

Java cannot find a class in a .jar file

$
0
0
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

Viewing all articles
Browse latest Browse all 40713

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>