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
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:
mainmethod when you link the application, using the
--mainflag, described below.
gijprogram, making sure that
gijcan find the libraries it needs.
-lgij, which links in the
mainroutine from the
gijcommand. This allows you to select the class whose
mainmethod you want to run when you run the application. You can also use other
gijflags, such as
-Dflags to set properties. Using the
-lgijlibrary (rather than the
gijprogram of the previous mechanism) has some advantages: it is compatible with static linking, and does not require configuring or installing libraries.
gij options relate to linking an executable:
mainmethod should be invoked when the resulting executable is run.
--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
This option is an alternative to using
--main; you cannot use both.
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