Java - Compile

> Procedural Languages > Java

1 - About

The compilation create a class source.class file from a java source file ie source.java 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))

Advertising

3 - Type

3.1 - javac utility

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

javac -sourcepath src -d build\classes src\com\gerardnico\HelloWorld.java

will create the file

build\classes\HelloWorld.class

3.2 - Code

4 - Library

The java compiler library is located at javax/tools/JavaCompiler. It is javax/tools/Tool (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)

pom.xml
<dependency>
    <groupId>jdk.tools</groupId>
    <artifactId>jdk.tools</artifactId>
    <scope>system</scope>
    <systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>

5 - Documentation / Reference

Advertising
lang/java/compile.txt · Last modified: 2019/05/14 14:11 by gerardnico