This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Jars & Zips & Classpath Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Jars & Zips & Classpath" Watch "Jars & Zips & Classpath" New topic

Jars & Zips & Classpath

Steven Armstrong

Joined: Sep 06, 2005
Posts: 4
This is something that has always vexed me - the installation of .jar files and setting the classpath. (Not to mention JAVA_HOME, installing the JDK, JRE, etc, but that's another story)

I'm working through the tutorials -- 'scuse me, the "Cattle Drive" --. I'm up to Assignment OOP-1, wherein it tells me that I will need to get jr.jar into my classpath. According to the FAQ, it's quite alright if jr.jar is really

I've followed the directions in the FAQ. I've copied it to my "C:\Program Files\Java\jre1.5.0_03\lib\ext" folder, I've reset the classpath to point to where the .zip file is, I've unzipped the file and THEN set the classpath for it's location. I still get "package com.javaranch.common does not exist.

I've fought with this same issue with other software packages. MANY times, and I don't know what's going wrong.

PLEASE, can SOMEONE explain it to me as if I were a six-year old?

Before you laugh at me too hard, remember, Albert Einstein said "If you can't explain something to a six-year-old, you don't understand it yourself."!
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
Given that jre is 'Java Runtime Environemt' and you need to have a jdk (Java Development Kit) installed to compile .java files, I'm guessing that you did everything right, except you put the jar in the wrong place relative to your javac.exe. (which I'll guess is in a folder named something like jdk1.5)
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
You don't need to put your custom jar files in the C:\Program Files\Java\jre1.5.0_03\lib\ext folder. In fact, I suggest that you DON'T do this. Instead, you should edit the system CLASSPATH variable to contain the JAR file itself. Note that the CLASSPATH must contain the JAR, not just the folder that contains the JAR. For example, if you have a JAR file named "myjar.jar" in a folder called "C:\myprogs", then your CLASSPATH should look like this:


I'm guessing that you have only tried to add the folder that contains the JAR and not the JAR file itself.

Let me know if this works for you.


Java API Documentation
The Java Tutorial
Marilyn de Queiroz

Joined: Jul 22, 2000
Posts: 9056
My only additional comment to Layne's description would be that if you already have a classpath set (and since you are reading the Cattle Drive instructions, I presume that you do), I would add the path to jr.jar to the the end of the existing classpath. So you might have
CLASSPATH = .;C:\Java;C:\Java\
for example.

I would not recommend putting it in the JRE\lib\ext folder either. And you'll be better off if you delete all the unzipped class files before they begin to cause confusion (although you might possibly want to look at the source files at some point).

"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Steven Armstrong

Joined: Sep 06, 2005
Posts: 4
You're right, I did have the CLASSPATH pointing to the folder, rather than to the .zip file.
So, here's what I did:
I removed the file from the lib\ext folder, and pasted it to my c:\Program Files\Java folder. I did not unzip the file.
I then changed the CLASSPATH to "c:\Program Files\Java\". Just to be sure, I restarted my machine.
I opened up BlueJ (My IDE of choice), wrote a stup program with a first line of "import com.javaranch.common.*; " and got the error message "package com.javaranch.common does not exist."
Next, since BlueJ is on my E: drive, I copied the file to "E:\BlueJ\lib", and edited the CLASSPATH to "c:\Program Files\Java\; E:\BlueJ\lib\ I rebooted the machine, tried to compile my stub program --- same error message.
Finally I changed the CLASSPATH to "E:\BlueJ\lib\", rebooted, recompiled, ... same thing.

I've always thought myself to be a reasonably intelligent person. What am I missing, here??

Thanks for the help thus far!
Joel McNary

Joined: Aug 20, 2001
Posts: 1824

Ah. IDEs are a whole different kettle o' beans.

Generally, an IDE ignores the system CLASSPATH. It instead sets up its own. Now, I don't use BlueJ, so I can't tell you how to set the path therein, but generally it's under the settings for the project that you are working in. You might try looking at the docs for BlueJ on how to set the classpath.

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Steven Armstrong

Joined: Sep 06, 2005
Posts: 4

That tidbit of information, sir, not only did the trick, but explains FINALLY why I've had so much vexation over the years with the same issue.

IDE's ignore the CLASSPATH, and use their own! (in the case of BlueJ, it's the sub folder "lib/userlib" A golden nugget of info that should be added to the teaching of CLASSPATHs, IMHO.

Now, I can get on with learning Java.
I agree. Here's the link:
subject: Jars & Zips & Classpath
It's not a secret anymore!