LinuxCommandLibrary

javac

Java source code compiler

TLDR

Compile a Java file

$ javac [File.java]
copy
Compile multiple files
$ javac [File1.java] [File2.java]
copy
Compile all Java files in current directory
$ javac *.java
copy
Compile with classpath
$ javac -cp [lib/*:classes] [File.java]
copy
Specify output directory for class files
$ javac -d [out] [File.java]
copy
Compile with specific Java version compatibility
$ javac --release [11] [File.java]
copy
Enable all warnings
$ javac -Xlint:all [File.java]
copy
Compile with verbose output
$ javac -verbose [File.java]
copy

SYNOPSIS

javac [OPTIONS] SOURCE-FILES
javac [OPTIONS] @ARGFILE

DESCRIPTION

javac compiles Java source files (.java) into bytecode class files (.class) that run on the Java Virtual Machine. It performs syntax and type checking, optimizes code, and generates platform-independent bytecode.
The compiler uses the classpath to locate referenced classes and libraries. For modular projects (Java 9+), the module path specifies module locations. The --release flag ensures compatibility with a specific Java version for both compilation and available APIs.
When compiling many files, use @argfiles to avoid command-line length limits. Each line in the argfile can contain a source file or option.

PARAMETERS

-d DIR

Output directory for compiled class files.
-cp, -classpath PATH
Classpath for finding user class files and libraries.
--module-path PATH
Module path for finding application modules.
-sourcepath PATH
Path for finding source files.
--release VERSION
Compile for specific Java SE release.
-source VERSION
Source code compatibility version.
-target VERSION
Generate class files for specific VM version.
-Xlint[:WARNINGS]
Enable warnings (all, deprecation, unchecked, etc.).
-g
Include debugging information.
-verbose
Output messages about what the compiler is doing.
-deprecation
Show description of deprecated API usage.
-encoding ENCODING
Source file character encoding.
-h DIR
Generate native header files for JNI.
@FILE
Read options and filenames from file.

CONFIGURATION

JAVA_HOME

Environment variable pointing to the JDK installation directory.
CLASSPATH
Environment variable specifying default class search paths for compilation.

CAVEATS

Source and class files must match Java package structure with directory paths. Circular dependencies between source files require all files to be compiled together. The classpath separator is : on Unix and ; on Windows.

HISTORY

javac has been part of the Java Development Kit since Java 1.0 in 1996. The compiler has evolved significantly, adding generics (Java 5), modules (Java 9), and numerous language features. Modern versions support incremental compilation and annotation processing.

SEE ALSO

java(1), jar(1), javadoc(1), jdb(1)

> TERMINAL_GEAR

Curated for the Linux community

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

$129.95
New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

New Raspberry Pi 3 Model B+ Board Raspberry PI 3B+

$54.00
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

$169.99
KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00