Sun Certified Programmer for the Java 2 Platform 1.4
Originally posted by Red Smith:
I think that you need to have the directory path of "com" in your -classpath argument
in order for this package
package com.example.model;
to be found by the compiler.
e.g.
The example is assuming that coffeeV1 is the root directory on the C drive.
Sun Certified Programmer for the Java 2 Platform 1.4
Originally posted by Amanda Albert:
The book has colons, not semicolons.
I will definitely submit the colon vs. semicolon error to the authors for the errata.
I modified your example slightly:
I think specifying "classes" in the -classpath is wrong too because based on the structure the authors outlined, we are compiling source code under the "src" directory. The "-d classes" option is what tells the compiler to put it in the "classes" directory. Am I wrong in this thinking?
Originally posted by Red Smith:
I think the compiler needs to look at the .class file of any classes used by the .java code it is compiling. For other than the standard Java classes provided by Sun, the compiler needs the -classpath, or the CLASSPATH environment variable,to find them (I believe it uses only one of those 2, not a combination). There is also some default search path the compiler makes (current directory and maybe more) if the -classpath and CLASSPATH are not set.
I don't think the -d option helps the compiler find input files, so you still need to specify paths to classes in the -classpath even if the -d is telling it where to place the output .class file.
[ August 12, 2007: Message edited by: Red Smith ]
Sun Certified Programmer for the Java 2 Platform 1.4
Originally posted by Amanda Albert:
%JAVA_HOME%;%TOMCAT_HOME%;%ANT_HOME%;C:\MyProjects\coffeeV1\classes;C:\MyProjects\webApp2\classes;
Originally posted by Amanda Albert:
Thanks for your help Red. So you're saying that if I set my CLASSPATH variables to point to the class directories of my projects, I won't need to use the -classpath option when compiling code?
So my CLASSPATH could look like this (and yes, I'm using Windows):
%JAVA_HOME%;%TOMCAT_HOME%;%ANT_HOME%;C:\MyProjects\coffeeV1\classes;C:\MyProjects\webApp2\classes;
etc etc.....
Originally posted by Red Smith:
The two directories you have at the end will be sufficient to compile any Java file you create, as long as all your compiled classes that aren't in packages are in those directories, and all the packages you create start in those directories.
Sun Certified Programmer for the Java 2 Platform 1.4
Originally posted by Ben Souther:
You can set it up as an environment variable (CLASSPATH) or pass it to the compiler/JVM as a command line switch. If you pass it on the command line when calling java or javac, the environment variable will be ignored.
There are some pitfalls to setting this up as an environment variable; especially if you have more than one project on your machine so a lot of books, these days, teach you to pass it via the command line switch.
There is no need for any of %JAVA_HOME%;%TOMCAT_HOME%;%ANT_HOME%
to be on your classpath. None of those directories contain java classes.
Sun Certified Programmer for the Java 2 Platform 1.4
Originally posted by Amanda Albert:
Thanks again Ben.
I'm always flustered about what settings to configure whenever I need to setup a machine so I can work on my Java apps. I figured the CLASSPATH environment variable helps point the computer to a lot of places at once. I guess I also need to learn more about what environment variables do .
Amanda
Don't get me started about those stupid light bulbs. |