GNU Java Training Wheels 1.1: How to build a collection of class files or an entire package

Next: How to invoke javadoc on a package, Previous: Importing a package from another package, Up: Packages in J.T.W. and Java [Contents][Index]

### 5.5 How to build a collection of class files or an entire package

When your class `X` uses another class `Y` in a different file then you need to add to the `build` target of your `Makefile` which is initially like so:

`build: clean`

to what follows:

`build: clean Y.java`

If your class `Y` is in another `package` such as the `class` `~/jtw-tutorials/path/to/dir/Y.class` i.e. in the `package` `path.to.dir` then you need to add to the build target of your `Makefile` like so:

`build: clean path/to/dir/Y.java`

This process should be repeated for every `class` that is called, directly or indirectly from your `main` `class` `X`. By applying this process to every file in your package, you can build an entire package, simply by invoking the `Makefile` command `make build`. To actually compile and run the `X` `class`, let `~/jtw-tutorials/path2/to/dir/X.class` be the location of the `X` `class`. Then you need to invoke the following `Makefile` target:

`make build `path2/to/dir/X.run``

The build target calls the "`clean`" target which deletes all `*.java` and `*.class` files directly or indirectly in the folder `~/jtw-tutorials`. If you don’t do this then `java` might run an old version of `*.class` files despite earlier errors in the build process. This is because the use of pipes in building and executing `*.class` files hides the return values of the programs `javac` and `java`.