Main Content

Java Compiler - needs all classes, compiles them all too

Archive - Originally posted on "The Horse's Mouth" - 2008-03-03 07:20:34 - Graham Ellis

Remember that when you compile a java source file ...

a) You must have the classes it will use when it runs available to the compiler so that it can check (a bit frustrating at times if you're compiling on one machine but going to be running on another)

b) If you supply only java course code for some of the classes used within the class you're compiling, or have updated the sources of those used classes, Java will automatically recompile them. (this can be a bit confusing when you see an error message referring to "line 65" and don't even have a line 65 in the file you've asked to be compiled - the error being in one of the other files)

Here's an example where I compiled a "Sales" application on last week's Java Course:

Dorothy:c2 grahamellis$ ls
Period.java Product.java Sales.java Single.java
Dorothy:c2 grahamellis$ javac Sales.java
Dorothy:c2 grahamellis$ ls
Period.class Product.class Sales.class Single.class
Period.java Product.java Sales.java Single.java
Dorothy:c2 grahamellis$


See that running here