SE450: Java Tools: javac [33/41] ![]() ![]() ![]() |
You will invoke the java compiler against the java source files you are trying to compile. You can use many command line options to make the compiler more sophisticated in how it deals with your code and bytecode.
For the example program above (in default package), you would run:
javac Hello.java
in the same directory where the Hello.java file would be located. This would compile the code and place the Hello.class file in the same directory.
You can also put the .class files in a different directory by using the
-d
command line option. So if your source files were
in src, and you wanted the class files in build, you can run
javac -d build src\Hello.java
To turn on debugging information for the debugger (more on this later)
you can run the javac command with the -g
option.
For the java program in a package, put the source code in a directory structure that matches the package structure. So the file Hello.java will be in a directory called example. The directory that contains the example directory is the package root. This is where we run the commands from. So the java compiler would be run as following: On Windows -
javac example\Hello.java
on Unix
javac example/Hello.java