• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Jars & Zips & Classpath

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 jr.zip.

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 jr.zip 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."!
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:

CLASSPATH=.;C:\myprogs\myjar.jar

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.

Layne
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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\jr.zip
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).
 
Steven Armstrong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 jr.zip 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\jr.zip". 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 jr.zip file to "E:\BlueJ\lib", and edited the CLASSPATH to "c:\Program Files\Java\jr.zip; E:\BlueJ\lib\jr.zip. I rebooted the machine, tried to compile my stub program --- same error message.
Finally I changed the CLASSPATH to "E:\BlueJ\lib\jr.zip", 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!
 
Bartender
Posts: 1844
Eclipse IDE Ruby Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Steven Armstrong
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
AHA!!

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.
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic