Next: Code Generation, Previous: Warnings, Up: Invoking gcj [Contents][Index]
To turn a Java application into an executable program,
you need to link it with the needed libraries, just as for C or C++.
The linker by default looks for a global function named main
.
Since Java does not have global functions, and a
collection of Java classes may have more than one class with a
main
method, you need to let the linker know which of those
main
methods it should invoke when starting the application.
You can do that in any of these ways:
main
method
when you link the application, using the --main
flag,
described below.
gij
program,
making sure that gij
can find the libraries it needs.
-lgij
, which links
in the main
routine from the gij
command.
This allows you to select the class whose main
method you
want to run when you run the application. You can also use
other gij
flags, such as -D
flags to set properties.
Using the -lgij
library (rather than the gij
program
of the previous mechanism) has some advantages: it is compatible with
static linking, and does not require configuring or installing libraries.
These gij
options relate to linking an executable:
--main=CLASSNAME
This option is used when linking to specify the name of the class whose
main
method should be invoked when the resulting executable is
run.
-Dname[=value]
This option can only be used with --main
. It defines a system
property named name with value value. If value is not
specified then it defaults to the empty string. These system properties
are initialized at the program’s startup and can be retrieved at runtime
using the java.lang.System.getProperty
method.
-lgij
Create an application whose command-line processing is that
of the gij
command.
This option is an alternative to using --main
; you cannot use both.
-static-libgcj
This option causes linking to be done against a static version of the libgcj runtime library. This option is only available if corresponding linker support exists.
Caution: Static linking of libgcj may cause essential parts
of libgcj to be omitted. Some parts of libgcj use reflection to load
classes at runtime. Since the linker does not see these references at
link time, it can omit the referred to classes. The result is usually
(but not always) a ClassNotFoundException
being thrown at
runtime. Caution must be used when using this option. For more
details see:
http://gcc.gnu.org/wiki/Statically%20linking%20libgcj
Next: Code Generation, Previous: Warnings, Up: Invoking gcj [Contents][Index]