Java - Compile (class file)


The compilation create a class source.class file from a java source file ie file.

The create class language is called Java - Bytecode (classfile) and can be run on any OS with any java executable (ie Java - Java Virtual Machine (JVM|Java))


javac utility


The javac utility permits to compile a the source file of a class

javac -sourcepath src -d build\classes src\com\gerardnico\

will create the file


To a specific java version

In order to to generate class files compatible with Java 1.4, use the following command line:

javac -source 1.4



Get the compiler version

To get the version of the target Java image used by javac (ie the java version), you can use javap

From the root directory of your project (normally src/java), execute the following command

javap -verbose com.domain.classname | grep "major"
  major version: 52


Java Version Major version
1.2 46
1.3 47
1.4 48
5 49
6 50
7 51
8 52
9 53
10 54
11 55


the java compiler library is located at javax/tools/JavaCompiler. It is javax/tools/Tool (Before the implementation of module in Java 9, bundled in <JDK_HOME>/lib/tools.jar)

A tool is a common interface tools that can be invoked from a program.

Add the compiler as dependency (see Maven doc)


Documentation / Reference

Powered by ComboStrap