LinuxCommandLibrary

javac

Reads Java class and interface definitions and compiles them into bytecode and class files.

TLDR

Compile a .java file

$ javac [file.java]
copy


Compile several .java files
$ javac [file1.java] [file2.java] [file3.java]
copy


Compile all .java files in current directory
$ javac [*.java]
copy


Compile a .java file and place the resulting class file in a specific directory
$ javac -d [path/to/directory] [file.java]
copy

Help

Usage: javac   
where possible options include:
  @                  Read options and filenames from file 
  -Akey[=value]                Options to pass to annotation processors 
  --add-modules (,)* 
        Root modules to resolve in addition to the initial modules, or all modules 
        on the module path if  is ALL-MODULE-PATH. 
  --boot-class-path -bootclasspath  
        Override location of bootstrap class files 
  --class-path -classpath -cp  
        Specify where to find user class files and annotation processors 
  -d                Specify where to place generated class files 
  -deprecation 
        Output source locations where deprecated APIs are used 
  --enable-preview 
        Enable preview language features. To be used in conjunction with either -source or --release. 
  -encoding          Specify character encoding used by source files 
  -endorseddirs          Override location of endorsed standards path 
  -extdirs               Override location of installed extensions 
  -g                           Generate all debugging info 
  -g:{lines,vars,source}       Generate only some debugging info 
  -g:none                      Generate no debugging info 
  -h  
        Specify where to place generated native header files 
  --help, -help, -?            Print this help message 
  --help-extra, -X             Print help on extra options 
  -implicit:{none,class} 
        Specify whether or not to generate class files for implicitly referenced files 
  -J                     Pass  directly to the runtime system 
  --limit-modules (,)* 
        Limit the universe of observable modules 
  --module -m  
        Compile only the specified module, check timestamps 
  --module-path -p  
        Specify where to find application modules 
  --module-source-path  
        Specify where to find input source files for multiple modules 
  --module-version  
        Specify version of modules that are being compiled 
  -nowarn                      Generate no warnings 
  -parameters 
        Generate metadata for reflection on method parameters 
  -proc:{none,only} 
        Control whether annotation processing and/or compilation is done. 
  -processor [,,...] 
        Names of the annotation processors to run; bypasses default discovery process 
  --processor-module-path  
        Specify a module path where to find annotation processors 
  --processor-path -processorpath  
        Specify where to find annotation processors 
  -profile  
        Check that API used is available in the specified profile 
  --release  
        Compile for a specific VM version. Supported targets: 6, 7, 8, 9, 10, 11 
  -s                Specify where to place generated source files 
  -source  
        Provide source compatibility with specified release 
  --source-path -sourcepath  
        Specify where to find input source files 
  --system |none          Override location of system modules 
  -target             Generate class files for specific VM version 
  --upgrade-module-path  
        Override location of upgradeable modules 
  -verbose                     Output messages about what the compiler is doing 
  --version, -version          Version information 
  -Werror                      Terminate compilation if warnings occur 

Copied to clipboard