tony1812
Posts: 354
Joined: Sat Jul 15, 2017 12:40 pm
Location: Boston MA.

where to put .jar?

Thu Sep 27, 2018 2:10 pm

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

User avatar
DougieLawson
Posts: 38885
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: where to put .jar?

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.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

tony1812
Posts: 354
Joined: Sat Jul 15, 2017 12:40 pm
Location: Boston MA.

Re: where to put .jar?

Thu Sep 27, 2018 6:30 pm

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?

User avatar
DougieLawson
Posts: 38885
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: where to put .jar?

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"
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All non-medical doctors are on my foes list.

JosAH
Posts: 66
Joined: Sat Nov 12, 2016 2:11 pm
Location: Voorschoten

Re: where to put .jar?

Fri Sep 28, 2018 3:10 pm

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

Return to “Java”