2

This seems to be very trivial. But I'm stuck for a while.

My CLASSPATH:

jerry@jerry-OptiPlex-790:~/Desktop/SQLLite-experiment/java$ echo $CLASSPATH
.:./*:/home/jerry/Desktop/SQLLite-experiment/java/jsqlparser-0.7.0.jar

Output of ll:

jerry@jerry-OptiPlex-790:~/Desktop/SQLLite-experiment/java$ ll
total 980
drwxrwxr-x 2 jerry jerry   4096 Apr 21 19:25 ./
drwxrwxr-x 7 jerry jerry   4096 Apr 21 17:05 ../
-rw-rw-r-- 1 jerry jerry 991221 Apr 21 17:25 jsqlparser-0.7.0.jar
-rw-rw-r-- 1 jerry jerry    181 Apr 21 19:24 test.java

My test.java file:

import net.sf.jsqlparser.statement.StatementVisitor;
import net.sf.jsqlparser.*;

public class test {

    public static void main(String[] args) {
        System.out.println("Hello");
    }
}

Output of javac:

jerry@jerry-OptiPlex-790:~/Desktop/SQLLite-experiment/java$ javac test.java 
test.java:1: error: package net.sf.jsqlparser.statement does not exist
import net.sf.jsqlparser.statement.StatementVisitor;
                                  ^
test.java:2: error: package net.sf.jsqlparser does not exist
import net.sf.jsqlparser.*;
^
2 errors

The below command also produces the same error:

jerry@jerry-OptiPlex-790:~/Desktop/SQLLite-experiment/java$ javac -cp "jsqlparser-0.7.0.jar:." test.java

The source for jsqlparser: http://jsqlparser.sourceforge.net/docs/

Could anyone please help me out with this issue? I also tried using this library on IntelliJ but it wasn't getting recognized. I followed through the standard procedure of adding an external library as stated in: How to add external library in IntelliJ IDEA?

FWIW I use tmux. Hope this isn't a issue with the CLASSPATH issue.

Community
  • 1
  • 1
Jerry Ajay
  • 1,084
  • 11
  • 26

2 Answers2

2

Look here for how to set classpath using command line options to any of the java sdk tools - java, javac. The page shows how to set the environment variable CLASSPATH as well as how to use the switch -classpath.

In your case if you have the jar in the same directory as your source files, then you will need a command like this to compile -

javac -classpath . MyClass.java

and this to run

java -classpath . MyClass

You can also provide the full path to a jar file in the classpath and add multiple directories and jars. Such as -classpath .:/path/to/my.jar:/some/other/directory

underdog
  • 4,447
  • 9
  • 44
  • 89
  • I'm perfectly aware of this. But, as stated in the question, the procedures I tried which included the ones you mentioned doesn't work in my case. – Jerry Ajay Apr 22 '15 at 00:08
  • try replacing the jar – underdog Apr 22 '15 at 00:34
  • Yup, I replaced the jar to another one `mail.jar`; the standard mail jar from oracle. It worked fine. So, I suppose it's a problem with the `jsqlparser` jar file. – Jerry Ajay Apr 22 '15 at 00:49
0

Ok, here's the solution I figured out after wasting hours. Seems stupid but still:... I just had to unzip the jar and use the jar file in the lib directory of the extracted jar.

Jerry Ajay
  • 1,084
  • 11
  • 26