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.

javac -d EXTERNAL_DIR SRC_FILE



Here are some examples,

javac -d D:\classes MyClass.java
javac -d D:\classes E:\java\MyClass.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.

No comments: