Compiling into a Directory Other Than Your Source Directory

     

It is common practice, and it's a good thing, to keep your source files in one directory and your class files in another. Typically, when you start a project you do something like this:

 

 /application root dir /application root dir/src /application root dir/classes 

You create two directories under the root of your application. Put all of your source files under the src directory and compile such that your classes go into the classes directory. Then you can use the JAR archiving tool to package just your classes and deploy those when your application is done.

By default, the javac tool compiles your classes into the same directory that the source file is in. So, you need to pass a command to the compiler to handle this. If you use an IDE such as Eclipse, you can almost always set the compiler output path in a project properties window.

To compile to a directory other than the one your source is in, use the -d flag, followed by the name of the directory you want the .class files to end up in.

 

 C:\j15\net\javagarage\demo\swing\      layouts>javac -source 1.5 -d C:\j15\classes GridLayoutExample.java 

The preceding example takes the file GridLayoutExample.java and compiles it into a class called GridLayoutExample.class under the C:\j15\classes directory with its packages intact. In other words, if the GridLayoutExample class is in a package called net.javagarage.swing.demo, you can find the class file in C:\j15\classes\net\javagarage\swing\demo.



Java Garage
Java Garage
ISBN: 0321246233
EAN: 2147483647
Year: 2006
Pages: 228
Authors: Eben Hewitt

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net