Page 1 of 1

where to put .jar?

Posted: Thu Sep 27, 2018 2:10 pm
by tony1812
Hello, I just started to learn java. I have a basic question. I don't want to use any IDEs, I want to use the Terminal to compile my jave code was written in a simple text editor. i wrote which require to import a .jar to the library. when I compile it in terminal, javac XYZ.java, where should the .jar go? on Desktop? Thanks

Re: where to put .jar?

Posted: Thu Sep 27, 2018 3:26 pm
by DougieLawson
It needs to be in a folder in your CLASSPATH or -cp when you try to run it. Java will only look for a jar file in folders defined on the CLASSPATH.

Re: where to put .jar?

Posted: Thu Sep 27, 2018 6:30 pm
by tony1812
DougieLawson wrote:
Thu Sep 27, 2018 3:26 pm
It needs to be in a folder in your CLASSPATH or -cp when you try to run it. Java will only look for a jar file in folders defined on the CLASSPATH.
That's what I figure.
How do I create this CLASSPATH?

Re: where to put .jar?

Posted: Thu Sep 27, 2018 7:33 pm
by DougieLawson
It's an environment variable so you could set it in ~/.bashrc or ~/.profile

If your jars are in a folder called ~/jar then stick that line at the bottom of ~/.profile

Code: Select all

CLASSPATH="$HOME/jar:$CLASSPATH"

Re: where to put .jar?

Posted: Fri Sep 28, 2018 3:10 pm
by JosAH
DougieLawson wrote:
Thu Sep 27, 2018 7:33 pm
It's an environment variable so you could set it in ~/.bashrc or ~/.profile

If your jars are in a folder called ~/jar then stick that line at the bottom of ~/.profile

Code: Select all

CLASSPATH="$HOME/jar:$CLASSPATH"
Using a global classpath variable is a bad idea in general. better define one as an argument (-claspath or -cp) to the jvm.

kind regards,

Jos