File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Starting Java: Hava a Classpath problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Starting Java: Hava a Classpath problem" Watch "Starting Java: Hava a Classpath problem" New topic
Author

Starting Java: Hava a Classpath problem

Eamon Nixon
Greenhorn

Joined: Jun 30, 2012
Posts: 10
Hi,
I have the following Classpath

*******************************************************************
CLASSPATH=C:\Users\Beatrice\Documents\NetBeansProjects\DotComBust\src\dotcombust
\;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;C:\Program Files\Java\jdk1.6.0_3
0\bin;c:\testProject
*******************************************************************************

I have already compiled GameHelper.java to GameHelper.class AND
DotCom.java to DotCom.class and both C;ass files INTO
c:\testProject

Now I try to compile DotComBust.java also in c:\testProject which implements the previous 2 classes(GameHelper+DotCom), but it gives me compile errors on all references to GameHelper and DotCom.

****************************************************************************************
C:\testProject>javac -cp . DotComBust.java
DotComBust.java:21: cannot find symbol
symbol : class GameHelper
location: class dotcombust.DotComBust
private GameHelper helper = new GameHelper();
^
DotComBust.java:22: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
private ArrayList<DotCom> dotComList = new ArrayList<DotCom>();
^
DotComBust.java:21: cannot find symbol
symbol : class GameHelper
location: class dotcombust.DotComBust
private GameHelper helper = new GameHelper();
^
DotComBust.java:22: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
private ArrayList<DotCom> dotComList = new ArrayList<DotCom>();
^
DotComBust.java:27: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom one = new DotCom();
^
DotComBust.java:27: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom one = new DotCom();
^
DotComBust.java:29: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom two = new DotCom();
^
DotComBust.java:29: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom two = new DotCom();
^
DotComBust.java:31: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom three = new DotCom();
^
DotComBust.java:31: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
DotCom three = new DotCom();
^
DotComBust.java:38: cannot find symbol
symbol : class DotCom
location: class dotcombust.DotComBust
for (DotCom dotComToSet : dotComList) {
^
11 errors
**************************************************************************************************************************

I have the correct classpath, but JAVAC isn't finding the classes.
I've tried javac -cp . DotComBust.java.
Any help would be appreciated?

Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Hello Eamon Nixon,

Welcome to CodeRanch!

It seems that you are trying to access class dotcombust.DotComBust, so you don't need to put package dotcombust in your classpath.

That is, your classpath should contain parent directory of dotcombust (instead of dotcombust itself).

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Anayonkar Shivalkar wrote: . . . That is, your classpath should contain parent directory of dotcombust (instead of dotcombust itself). . . .
Disagree.

It is usually best not to set a system classpath at all, but some applications set it for you while you aren’t watching. QuickTime is notorious for doing that. Delete the references to dotcom, test project and the jdk from the classpath. They should not be in a system classpath. If you need a classpath, you should set it with the -cp tags. If you are at the dotcom stage, you don’t yet need to know about -cp. Change your classpath to read
CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
Note the .; at the beginning. That will take you to your “current” directory as a default, which is what you usually want.
You will have to navigate to the correct directory for dotcom. I would suggest you //comment out the package names from all your dotcom classes and use the directory they are in as an unnamed package.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
And again welcome to the Ranch
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Campbell Ritchie wrote:Disagree.

So, problem is not with classpath? And parent directory should not be part of classpath?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
There probably is a problem with the classpath, but the ideal system classpath is completely empty. Lots of books advise you to set a system classpath, but that is usually mistaken and usually does more harm than good. If beginners download code with package names in, the package names tend to confuse them because compiling packages is awkward without Ant or an IDE. So the best thing for beginners is not to set a classpath at all, and use the current directory as an unnamed package.

Once you start using more than about a dozen classes, you are out of the realms of small applications (as it said in that Java™ tutorials link I posted), and that is the point to start learning about packages. Probably the point to start learning to use an IDE, too. When you start writing large applications which require downloaded .jars (or similar) along with your application, those resources will be stored somewhere on your computer, and you need to add those .jars to your classpath. But they will be different for each application, so you need a new classpath for each application.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1509
    
    5

Yes. I agree with that. Its much better to use -cp instead of CLASSPATH env variable.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Eamon Nixon
Greenhorn

Joined: Jun 30, 2012
Posts: 10
Campbell Ritchie wrote:
Anayonkar Shivalkar wrote: . . . That is, your classpath should contain parent directory of dotcombust (instead of dotcombust itself). . . .
Disagree.

It is usually best not to set a system classpath at all, but some applications set it for you while you aren’t watching. QuickTime is notorious for doing that. Delete the references to dotcom, test project and the jdk from the classpath. They should not be in a system classpath. If you need a classpath, you should set it with the -cp tags. If you are at the dotcom stage, you don’t yet need to know about -cp. Change your classpath to read
CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip
Note the .; at the beginning. That will take you to your “current” directory as a default, which is what you usually want.
You will have to navigate to the correct directory for dotcom. I would suggest you //comment out the package names from all your dotcom classes and use the directory they are in as an unnamed package.

Great Stuff..
//commented the package reference
Added .; as current directory classpath and deleted the others.
Thanks for tutorial link on packages also. I do read these things.
Works perfectly, never would have figured it out. Forums, wonderful places.
Great Welcome gentlemen.
Thanks for your help. Can move on to next 5 meter wall now. Then, I'll be back.
Dont worry ranch hands, I search the forums for answers before I post.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39415
    
  28
Eamon Nixon wrote: . . . Can move on to next 5 meter wall now. . . .
It will be the next 5″ wall that catches you out

And you’re welcome We have all seen such problems before.
 
jQuery in Action, 2nd edition
 
subject: Starting Java: Hava a Classpath problem