Re: extends "cannot be resolved to a type"



Oliver Wong wrote:
Did you try compiling the files while ensuring that the current directory be ~ben/docs/comp/lang/java/ ? Did you ensure that "." (the current directory) is part of the CLASSPATH environment variable?

Ben Collver wrote:
Yes to the former, no to the latter. Adding "." to the CLASSPATH environment variable fixes my problem on the Linux box.

My main system has no CLASSPATH environment variable. Since it has no problem, I guess its Java has a built-in class path with "."

Java has no "built-in class path", but your Windows box might.

Generally it is better to script (preferably with Ant) the classpath, invoking the -cp (-classpath) option to the 'java' command, rather than to use the CLASSPATH envar. CLASSPATH is global and inflexible, whereas "-cp" is particular and adaptable.

Also, it is a Bad Thing to use the "default package" for classes.

Better is to use a (possibly fictional) domain, for example "lewscanon.com", invert the top- and second-level domains and add your package name, like this:

com.lewscanon.example.package

which in most filesystems for most class loaders would correspond to the relative path

com/lewscanon/example/package/

in which your Foo class bytecode would appear as

com/lewscanon/example/package/Foo.class

"Relative to what?" you ask? Great question - relative to the first classpath element that has such a subdirectory.

These matters are covered in Sun's tutorial.

-- Lew
.



Relevant Pages

  • package from hell
    ... my environmental variable classpath on W2K is ... Java Programming Center" written by Dana Nourie. ... The package consists of the main class named "DiveLog.java" and a series ... while in C:\divelog I used the following cmd to compile DiveLog.java. ...
    (comp.lang.java.help)
  • Re: command-line main() classpath etc.
    ... > from the classpath and command-line args. ... you've not divulged the package portion. ... name you must supply on the java command line; ...
    (comp.lang.java.programmer)
  • Re: import, classpath, and directories
    ... To avoid class ... > the new folder in my CLASSPATH. ... Put each project in a separate package. ... Project1 classes are in package project1 and the directory ...
    (comp.lang.java.programmer)
  • cant run from command line
    ... This is what my classpath is set to: ... package myHomework; ... NumberComparer (wrong ...
    (comp.lang.java.help)
  • Re: importing external class from inside package
    ... discusses package and other name conventions. ... Common usage extends the package name convention such that all package name components comprise lower-case characters. ... The safest is just to include the classpath at every step, and ensure that it contains the root of the various package trees. ... It's safer to root your command line at a parent directory, safer still to root your commands at a project directory and let a script sort out the relative path roots, safest of all to use Ant or one of the build platforms out there. ...
    (comp.lang.java.help)