Results 1 to 2 of 2

Thread: Java cannot find a class in a .jar file

  1. #1
    Join Date
    Feb 2009
    Location
    Concordia, MO, USA
    Posts
    156

    Default 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

  2. #2
    Join Date
    May 2010
    Location
    Space Colony Lagrange Point 22° à, 77° Ƅ, 56° ɤ, 99° ɜ
    Posts
    3,166

    Default Re: Java cannot find a class in a .jar file

    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/AN...+with+ANTLR+v4

    Proof :-

    Only thing i did differently was
    Code:
    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/Jav..._7_0-sun-devel


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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •