Compiling Java on Debian GNU/Linux

The easiest way to get a command-line Java compiler in GNU/Linux is to use Debian's package management system, the Advanced Package Tool (APT).

Currently, the best Java free software compiler is GCJ. GCJ is the Java-front end to the GNU Compiler Collection (GCC). Since running GCJ and GCC requires a lot of development software and libraries, it is best to let Debian handle the dependencies for you.

Installing GCJ

To install the GCJ package, run the following:

$ apt-get install gcj libgcj-dev

This will install gcj and the basic Java development libraries and headers.

Compling with GCJ

Compiling then becomes as easy as:

$ gcj
To compile the resulting class file file.class into an executable and using a method called Main, run he following:

$ gcj --main=Main -o file file.class


The scenario above completely beats building a snapshot of libgcj and GCJ on your own. Though, Debian won't always have the most recent release or snapshot of the compiler.

GCJ supports the other tools in the GNU tool set, including being able to debug Java with the GNU Debugger (GDB).

Site maintained by Aaron Hawley
$Id: debian.html,v 1.5 2007/08/07 20:30:07 ashawley Exp $

Permission is granted to copy, distribute and/or modify these web pages on "Free Java" under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with the Front-Cover Text being "A free book about free software", and Back-Cover Texts being "You have freedom to copy and modify this book".