File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Another CLASSPATH problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Another CLASSPATH problem" Watch "Another CLASSPATH problem" New topic

Another CLASSPATH problem

Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
I've been cruising along nicely until I tried creating my first package. I'm working out of chapter 5 in Thinking in Java and I'm having the following problem.
First, the preliminaries... I'm working on Windows 95 using JDK 1.3. My CLASSPATH is:
SET CLASSPATH=.;C:\jdk1.3\bin;C:\javaprog;C:\javaprog\;
In my javaprog directory I have the following file:

In the c:\javaprog\mypackage folder I have the following file compiles fine, but I get the following error when I compile
[Windows 95] C:\javaprog>javac cannot access MyClass
bad class file: .\MyClass.class
class file contains wrong class: mypackage.MyClass
Please remove or make sure it appears in the correct subdirectory of the classpa
new MyClass() ;
1 error
I have things setup the same way on a Win 2K system and it works fine, but I'm at a loss as to why it doesn't work on my home Win 95 system.
I have a suspicion that the solution to this is staring me in the face, but I'm not seeing it. I would appreciate any insight anyone here could offer.
Thanks in advance,
Pat B.
Andy Ceponis
Ranch Hand

Joined: Dec 20, 2000
Posts: 782
Well im no expert on 95 or anything, since all i use is 2k. But i think this may have something to do with your prob.
SET CLASSPATH=.;C:\jdk1.3\bin;C:\javaprog;C:\javaprog\;
Ok, so thats your path. But later on you say that your package is in c:\javaprog\mypackage.
Now im not sure on this, but shouldnt you include the /mypackage directory in your classpath?
Pat Barrett
Ranch Hand

Joined: Jan 03, 2001
Posts: 63
Thanks for the reply Andy,
Your answer wasn't the right one, but it got me to realize what the problem actually was. Before I got to the part in the TIJ book about saving all your package files in their own directory I had originally saved and compiled myClass in the javaprog directory. Later, I added the mypackage directory and rather than moving the file I copied it, leaving a different version of myClass in the javaprog directory. Since the CLASSPATH just provides a starting point for the compiler to look for the necessary packages it was hitting my original myClass, which was the cause of the error.
I hate to admit such a mindless error, but hopefully this will help someone else down the road.
Thanks again,
Pat B.
I agree. Here's the link:
subject: Another CLASSPATH problem
It's not a secret anymore!