Cannot find Symbol

Hello,

I am working on a small project and I am having trouble compiling one of my classes. I have an instance of a class that is defined from this class and when I compile the class from the command line, it says cannot find symbol. Both classes are in the same package and all capitalization has been checked. My PATH is set, so that is not a problem. Any ideas?

[377 byte] By [dwillynta] at [2007-9-30 2:24:59]
# 1
Your PATH may be set, but what about your CLASSPATH?
paulcwa at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 2
Don't have one. So do I just go into my environment variables and create a variable named CLASSPATH and point it to the folder where I am working on my project?
dwillynta at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 3

I usually set my classpath to point to common libraries that are used among multiple projects.

These are generally libraries that I use but didn't write myself -- standard tools for processing XML, say.

For individual projects, I usually use the -classpath option.

Also, I keep my source in a directory structure that follows the package structure. Then I compile like this

javac -classpath ./classes:$CLASSPATH -d classes -sourcepath src src/path/to/the/class/im/Compiling.java

So, it looks in classes directory (under the project directory) for compiled classes that are part of the project, the src directory for the source files, and puts the compiled class files in classes.

That's for non-trivial but not very big projects. For a bigger project, I just use Eclipse. For trivial stuff, everything's in the current directory and there are no packages, so it's just:

javac *.java

paulcwa at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 4

OK, maybe my syntax is wrong but I tried this to compile.

javac -classpath .\DatabaseUtilities.class -sourcepath C:\Documents and Settings\pcu01\Desktop\Darin\GraphBuilder\GraphMaker.java

This did not work, what am I doing wrong. I take it that the .\ is to search in the source directory.

dwillynta at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 5

The purpose of the -classpath and -sourcepath options is to tell the compiler what directories to look in to find stuff. It shouldn't point to individual files. Also, the compiler and JVM take these arguments to mean the top of a directory hiearchy that follows the package names.

sourcepath is only used if the compiler needs to find additional source code files.

paulcwa at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 6

So if "GraphBuilder" is a package, and DatabaseUtilities has no package and you've compiled it and left the compiled class file in the current directory, and if you're currently in the C:\Documents and Settings\pcu01\Desktop\Darin\directory, and you're not using any additional libraries etc., then you'd call:

javac -classpath . GraphBuilder\GraphMaker.java

If you've taken my advice and kept your classes in a separate directory called "classes" and your source in a separate directory called "src", you'd do:

javac -classpath classes src\GraphBuilder\GraphMaker.java

and if GraphMaker depends on another class that hasn't been compiled yet, you'd do:

javac -classpath classes -sourcepath src src\GraphBuilder\GraphMaker.java

The ".\" means "the current directory".

paulcwa at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...
# 7

Okay, thanks for your help. I think something is fishy with my install of Java. It will now go through the motions of compiling, but will not compile. I did -verbose and it did not show the writing of class file. It also did not error out, and It did look in the directory where I have my class file. I will uninstall and reinstall and see if this helps. Thanks for your help.

dwillynta at 2007-7-16 13:34:41 > top of Java-index,Archived Forums,New To Java Technology Archive...