tony1812
Posts: 350
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: 34167
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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.
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

tony1812
Posts: 350
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: 34167
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website

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"
Microprocessor, Raspberry Pi & Arduino Hacker
Mainframe database troubleshooter
MQTT Evangelist
Twitter: @DougieLawson

2012-18: 1B*5, 2B*2, B+, A+, Z, ZW, 3Bs*3, 3B+

Any DMs sent on Twitter will be answered next month.

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”