How to compile Java files to external directory

Compile java source files to external directory
Here is a simple thing that you can do to compile your java source files to an external directory other than the java source directory. All you need to do is to work with javac with which you will compile classes daily. It has a command line option which will do the job. Here is it.


Here are some examples,

javac -d D:\classes
javac -d D:\classes E:\java\

Note that -d represents a directory and that you'll have to specify a directory to store the class files but not a file. Also, the directory where the class files should be stored must exist. The source file of course must exist first of all.

You can see javac -help for more options.

Posted by at on

Tags: Tips,